-
Image: 有領“好人卡”傾向的廣大程式猿一定對 映象 的概念不會陌生。但和 Windows 的那種 ISO 映象相比,Docker 中的映象是分層的,可復用的,而非簡單的一堆檔案迭在一起(類似於一個壓縮包的原始碼和一個 Git 倉庫的區別)。
-
Container: 容器的存在離不開映象的支援,他是映象執行時的一個載體(類似於實體和類的關係)。依託 Docker 的虛擬化技術,給容器建立了獨立的埠、行程、檔案等“空間”,Container 就是一個與宿機隔離 “容器”。容器可宿主機之間可以進行 port、volumes、network 等的通訊。
-
Repository: Docker 的倉庫和 Git 的倉庫比較相似,擁有倉庫名、tag。在本地構建完映象之後,即可透過倉庫進行映象的分發。常用的 Docker hub 有 https://hub.docker.com/ 、 https://cr.console.aliyun.com/ 等。
> docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
c448d9b1e62f: Pull complete
0277fe36251d: Pull complete
6591defe1cd9: Pull complete
2c321da2a3ae: Pull complete
08d8a7c0ac3c: Pull complete
Digest: sha256:2152a8e6c0d13634c14aef08b6cc74cbc0ad10e4293e53d2118550a52f3064d1
Status: Downloaded newer image for ubuntu:18.04
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 18.04 58c12a55082a 44 hours ago 79MB
> docker create --name ubuntuContainer ubuntu:18.04
0da83bc6515ea1df100c32cccaddc070199b72263663437b8fe424aadccf4778
> docker start ubuntuContainer
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9298a27262da ubuntu:18.04 "/bin/bash" 4 minutes ago Up About a minute ubuntuContainer
> docker exec -it 9298
root@9298a27262da:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@9298a27262da:/# exit
> docker run -it --name runUbuntuContainer ubuntu:18.04 /bin/bash
root@57cdd61d4383:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@57cdd61d4383:/#
# docker ps 可以查到已經成功運行了 runUbuntuContainer
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
57cdd61d4383 ubuntu:18.04 "/bin/bash" 9 seconds ago Up 8 seconds runUbuntuContainer
9298a27262da ubuntu:18.04 "/bin/bash" 9 minutes ago Up 6 minutes ubuntuContainer
> apt-get update
> apt-get install wget
> wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
# 安裝完之後可能當前 session 讀不到 nvm 命令,可以 exit 之後再進入終端環境
> nvm install 8.0.0
> node -v
> docker commit --author "rccoder" --message "curl+node" 9298 rccoder/myworkspace:v1
sha256:68e83119eefa0bfdc8e523ab4d16c8cf76770dbb08bad1e32af1c872735e6f71
# 透過 docker images 就能看到新製作的 rccoder/myworkspace 就躺在這裡了
>docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
rccoder/myworkspace v1 e0d73563fae8 20 seconds ago 196MB
> docker run -it --name newWorkSpace rccoder/myworkspace:v1 /bin/bash
root@9109f6985735:/# node -v
8.0.0
> docker login
> docker push rccoder/myworkspace:v1
The push refers to repository [docker.io/rccoder/myworkspace]
c0913fec0e19: Pushing [=> ] 2.783MB/116.7MB
bb1eed35aacf: Mounted from library/ubuntu
5fc1dce434ba: Mounted from library/ubuntu
c4f90a44515b: Mounted from library/ubuntu
a792400561d8: Mounted from library/ubuntu
6a4e481d02df: Waiting
# Comment
INSTRUCTION arguments
FROM rccoder/myworkspace:v1
RUN mkdir a
> docker build -t newfiledocker:v1 .
Sending build context to Docker daemon 3.584kB
Step 1/2 : FROM rccoder/myworkspace:v1
---> 68e83119eefa
Step 2/2 : RUN mkdir a
---> Running in 1127aff5fbd3
Removing intermediate container 1127aff5fbd3
---> 25a8a5418af0
Successfully built 25a8a5418af0
Successfully tagged newfiledocker:v1
# 新建基於 newfiledocker 的容器併在終端中開啟,發現裡面已經有 a 檔案夾了。
> docker docker run -it newfiledocker:v1 /bin/bash
root@e3bd8ca19ffc:/# ls
a bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
-
https://docs.docker.com/docker-for-mac/install/#install-and-run-docker-for-mac
-
https://travis-ci.org/
-
https://docs.docker.com/engine/reference/builder/#environment-replacement
-
https://github.com/cnpm/nodeinstall
-
https://docs.docker.com/engine/reference/commandline/cli/
-
https://docs.docker.com/engine/reference/builder/
-
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/