您好,登錄后才能下訂單哦!
docker commit [選項] 容器ID/名稱 倉庫名稱:[標簽]
-m:說明信息
-a:作者信息
-p:生成過程中停止容器的運行
[root@localhost ~]# docker pull centos //下載鏡像
[root@localhost ~]# docker create -it centos /bin/bash //基于centos鏡像創建容器
30d395e63fc32b9dcf96029869f40a8002990f689410cca2660af4056ed2614f
[root@localhost ~]# docker ps -a //查看容器信息
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
30d395e63fc3 centos "/bin/bash" 7 seconds ago Created inspiring_germain
[root@localhost ~]# docker commit -m "new" -a "daoke" 30d395e63fc3 daoke:centos //將容器里面運行的程序及運行環境打包生成新的鏡像
sha256:66d76f9225b94ce6156db953bd16c384f74067f981d45bee99340f3a965506d3
[root@localhost ~]# docker images //查看鏡像
REPOSITORY TAG IMAGE ID CREATED SIZE
daoke centos 66d76f9225b9 10 seconds ago 220MB
centos latest 0f3e07c0138f 3 months ago 220MB
[root@localhost ~]# mount.cifs //192.168.100.3/LNMP-C7 /mnt/ //將本地模板掛載到Linux上
Password for root@//192.168.100.3/LNMP-C7:
[root@localhost ~]# cd /mnt //切換目錄到/mnt
[root@localhost docker]# ls
debian-7.0-x86-minimal.tar.gz
[root@localhost mnt]# cat debian-7.0-x86-minimal.tar.gz | docker import - daoke:new //基于本地模板創建一個鏡像
sha256:487145d2411f0440c50fd93d0e8a9e27610d2de745a25d06955f21c80e65753a
[root@localhost mnt]# docker images //查看鏡像
REPOSITORY TAG IMAGE ID CREATED SIZE
daoke new 487145d2411f 8 seconds ago 215MB
centos latest 0f3e07c0138f 3 months ago 220MB
[root@localhost ~]# mkdir apache //創建一個目錄
[root@localhost ~]# cd apache/
[root@localhost apache]# vim Dockerfile //編寫一個dockerfile文件
FROM centos //基于的基礎鏡像
MAINTAINER The porject <xu> //維護鏡像的用戶信息
RUN yum -y update //鏡像操作指令安裝Apache軟件
RUN yum -y install httpd //安裝Apache服務
EXPOSE 80 //開啟80端口
ADD index.html /var/www/html/index.html //復制網址首頁文件
ADD run.sh /run.sh //將執行腳本復制到鏡像中
RUN chmod 755 /run.sh
CMD ["/run.sh"] //啟動容器時執行腳本
[root@localhost apache]# vim run.sh //編輯run.sh腳本
#!/bin/bash
rm -rf /run/httpd/* //清除緩存
exec /usr/sbin/apachectl -D FOREGROUND //執行apache
[root@localhost apache]# echo "this is test web" > index.html //創建頁面信息
[root@localhost apache]# ls
Dockerfile index.html run.sh
[root@localhost apache]# docker build -t httpd:centos . //執行創建鏡像
[root@localhost apache]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd centos b267aaf2c395 22 seconds ago 401MB
[root@localhost apache]# docker ps -a //此時沒有容器生成
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost apache]# docker run -d -p 1234:80 httpd:centos //創建映射,創建容器
34c424efdab9e381116de697c4971200b1564b1e38644407cc58d5ba8923a0ea
[root@localhost apache]# docker ps -a //容器開啟,1234是外部端口,80是內部端口
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34c424efdab9 httpd:centos "/run.sh" 9 seconds ago Up 7 seconds 0.0.0.0:1234->80/tcp great_williamson
//需要注冊docker賬號
//將創建好的 httpd:centos 鏡像。上傳到剛申請的公共倉庫中:
docker tag httpd:centos xu/httpd:centos
docker push xu/httpd:centos
[root@localhost ~]# docker pull registry //下載 registry鏡像
[root@localhost ~]# vim /etc/docker/daemon.json
{
"insecure-registries": ["192.168.13.128:5000"], //指定倉庫地址和端口號
"registry-mirrors": ["https://3a8s9zx5.mirror.aliyuncs.com"] //鏡像加速
}
[root@localhost ~]# systemctl stop docker //停止docker,開啟docker
[root@localhost ~]# systemctl start docker
[root@localhost ~]# docker create -it registry /bin/bash //創建registry鏡像容器
209dadd90f5c555ba328fae5763a61ae5fe4489acc4bfb945a99bb2307a9f139
[root@localhost ~]# docker ps -a //查看容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
209dadd90f5c registry "/entrypoint.sh /bin…" 4 seconds ago Created admiring_dewdney
34c424efdab9 httpd:centos "/run.sh" 13 minutes ago Exited (137) 35 seconds ago great_williamson
[root@localhost ~]# docker start 209dadd90f5c //開啟容器
209dadd90f5c
[root@localhost ~]# docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry //創建映射端口和數據卷,宿主局的/data自動掛載容器重點的/tmp
fd4185499dfa29f1a1133f59b706a5524572ae3f22140137214ab4c8212ea8a4
[root@localhost ~]# docker images //查看一下當前的鏡像
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd centos b267aaf2c395 17 minutes ago 401MB
centos latest 0f3e07c0138f 3 months ago 220MB
registry latest f32a97de94e1 10 months ago 25.8MB
[root@localhost ~]# docker tag httpd:centos 192.168.13.128:5000/httpd //修改標簽
[root@localhost ~]# docker push 192.168.13.128:5000/httpd ##上傳鏡像
[root@localhost ~]# curl -XGET http://192.168.13.128:5000/v2/_catalog //獲取私有倉庫列表
{"repositories":["httpd"]}
[root@localhost ~]# docker pull 192.168.13.128:5000/httpd //通過私有倉庫下載
[root@localhost ~]# docker run -d -P nginx //隨機指定端口
[root@localhost ~]# docker ps -a //查看容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bcd11c99804e nginx "nginx -g 'daemon of…" 13 seconds ago Up 13 seconds 0.0.0.0:32768->80/tcp
[root@localhost ~]# docker run -itd -P --name web1 centos /bin/bash //創建web1容器
87c58af3100fbc112bf344a421942dd53451c0c663b697a55a8d410868f314bf
[root@localhost ~]# docker run -itd -P --name web2 --link web1:web1 centos /bin/bash //創建web2連接web1容器
7a84075802b5689912c323196b5af398fb5912316efda014921c0e23d3e9cdd2
[root@localhost ~]# docker ps -a //查看容器信息
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7a84075802b5 centos "/bin/bash" 6 seconds ago Up 5 seconds web2
87c58af3100f centos "/bin/bash" 42 seconds ago Up 41 seconds web1
[root@localhost ~]# docker exec -it 7a84075802b5 /bin/bash //進入web2容器
[root@7a84075802b5 /]# ping web1 //pingweb1看是否互聯互通
PING web1 (172.17.0.5) 56(84) bytes of data.
64 bytes from web1 (172.17.0.5): icmp_seq=1 ttl=64 time=0.090 ms
64 bytes from web1 (172.17.0.5): icmp_seq=2 ttl=64 time=0.089 ms
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。