docker commit [選項(xiàng)] 容器ID/名稱 倉(cāng)庫(kù)名稱:[標(biāo)簽]
-m:說(shuō)明信息
-a:作者信息
-p:生成過(guò)程中停止容器的運(yùn)行
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:申請(qǐng)域名、虛擬主機(jī)、營(yíng)銷軟件、網(wǎng)站建設(shè)、南寧網(wǎng)站維護(hù)、網(wǎng)站推廣。
[root@localhost ~]# docker pull centos //下載鏡像
[root@localhost ~]# docker create -it centos /bin/bash //基于centos鏡像創(chuàng)建容器
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 //將容器里面運(yùn)行的程序及運(yùn)行環(huán)境打包生成新的鏡像
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 //基于本地模板創(chuàng)建一個(gè)鏡像
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 //創(chuàng)建一個(gè)目錄
[root@localhost ~]# cd apache/
[root@localhost apache]# vim Dockerfile //編寫一個(gè)dockerfile文件
FROM centos //基于的基礎(chǔ)鏡像
MAINTAINER The porject <xu> //維護(hù)鏡像的用戶信息
RUN yum -y update //鏡像操作指令安裝Apache軟件
RUN yum -y install httpd //安裝Apache服務(wù)
EXPOSE 80 //開(kāi)啟80端口
ADD index.html /var/www/html/index.html //復(fù)制網(wǎng)址首頁(yè)文件
ADD run.sh /run.sh //將執(zhí)行腳本復(fù)制到鏡像中
RUN chmod 755 /run.sh
CMD ["/run.sh"] //啟動(dòng)容器時(shí)執(zhí)行腳本
[root@localhost apache]# vim run.sh //編輯run.sh腳本
#!/bin/bash
rm -rf /run/httpd/* //清除緩存
exec /usr/sbin/apachectl -D FOREGROUND //執(zhí)行apache
[root@localhost apache]# echo "this is test web" > index.html //創(chuàng)建頁(yè)面信息
[root@localhost apache]# ls
Dockerfile index.html run.sh
[root@localhost apache]# docker build -t httpd:centos . //執(zhí)行創(chuàng)建鏡像
[root@localhost apache]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd centos b267aaf2c395 22 seconds ago 401MB
[root@localhost apache]# docker ps -a //此時(shí)沒(méi)有容器生成
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost apache]# docker run -d -p 1234:80 httpd:centos //創(chuàng)建映射,創(chuàng)建容器
34c424efdab9e381116de697c4971200b1564b1e38644407cc58d5ba8923a0ea
[root@localhost apache]# docker ps -a //容器開(kāi)啟,1234是外部端口,80是內(nèi)部端口
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
//需要注冊(cè)docker賬號(hào)
//將創(chuàng)建好的 httpd:centos 鏡像。上傳到剛申請(qǐng)的公共倉(cāng)庫(kù)中:
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"], //指定倉(cāng)庫(kù)地址和端口號(hào)
"registry-mirrors": ["https://3a8s9zx5.mirror.aliyuncs.com"] //鏡像加速
}
[root@localhost ~]# systemctl stop docker //停止docker,開(kāi)啟docker
[root@localhost ~]# systemctl start docker
[root@localhost ~]# docker create -it registry /bin/bash //創(chuàng)建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 //開(kāi)啟容器
209dadd90f5c
[root@localhost ~]# docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry //創(chuàng)建映射端口和數(shù)據(jù)卷,宿主局的/data自動(dòng)掛載容器重點(diǎn)的/tmp
fd4185499dfa29f1a1133f59b706a5524572ae3f22140137214ab4c8212ea8a4
[root@localhost ~]# docker images //查看一下當(dāng)前的鏡像
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 //修改標(biāo)簽
[root@localhost ~]# docker push 192.168.13.128:5000/httpd ##上傳鏡像
[root@localhost ~]# curl -XGET http://192.168.13.128:5000/v2/_catalog //獲取私有倉(cāng)庫(kù)列表
{"repositories":["httpd"]}
[root@localhost ~]# docker pull 192.168.13.128:5000/httpd //通過(guò)私有倉(cāng)庫(kù)下載
[root@localhost ~]# docker run -d -P nginx //隨機(jī)指定端口
[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 //創(chuàng)建web1容器
87c58af3100fbc112bf344a421942dd53451c0c663b697a55a8d410868f314bf
[root@localhost ~]# docker run -itd -P --name web2 --link web1:web1 centos /bin/bash //創(chuàng)建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 //進(jìn)入web2容器
[root@7a84075802b5 /]# ping web1 //pingweb1看是否互聯(lián)互通
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
文章題目:Docker容器之鏡像管理,端口映射,容器互聯(lián)
鏈接分享:http://jinyejixie.com/article12/ipjjgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、微信公眾號(hào)、手機(jī)網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、網(wǎng)站設(shè)計(jì)、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
網(wǎng)頁(yè)設(shè)計(jì)公司知識(shí)