在按照本文檔的步驟操做前,須要安裝好 Dockerhtml
Docker Image 的發佈linux
方法1:保存 Image 到 tar 包docker
語法:docker save -o 導出的鏡像名.tar 本地鏡像名:鏡像標籤apache
[root@Docker docker-build]# docker save -o centos-httpd-docker-image.tar centos:httpd
[root@Docker docker-build]# ll -h
total 275M
-rw-r--r--. 1 root root 154 May 17 23:19 Dockerfile
-rw-------. 1 root root 275M May 17 23:37 centos-httpd-docker-image.tar
-rw-r--r--. 1 root root 37 May 17 23:27 index.html
-rwxr-xr-x. 1 root root 29 May 17 23:25 start.shcentos
使用導入本地鏡像瀏覽器
[root@Docker docker-build]# docker rmi -f centos:httpd #刪除鏡像,這裏寫本身鏡像的 ID 或名稱bash
[root@Docker docker-build]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos apache b8822ec8a7bb 27 minutes ago 280MB
centos latest 470671670cac 4 months ago 237MB
[root@Docker docker-build]# docker load -i centos-httpd-docker-image.tar
Loaded image: centos:httpd
[root@Docker docker-build]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos httpd 85b4a3657ced 8 minutes ago 280MB
centos apache b8822ec8a7bb 29 minutes ago 280MB
centos latest 470671670cac 4 months ago 237MBapp
方法 2:Push Image To Docker Hub 發佈到外網tcp
一、Signup on docker hub & create repo 註冊一個賬號
https://hub.docker.com/
二、Login to docker hub測試
三、Push image to docker hub #上傳鏡像
四、Pull image from docker hub #下載鏡像
Container 容器端口映射
實戰:Container 端口映射
啓動 container
[root@Docker ~]# docker run -d -p 80:80 centos:httpd /bin/bash -c /usr/local/bin/start.sh
cf183879c15bd06523ecb6b5e19aec561d679fa5f3bd1842cb2d2994f0d79b04
注: -p 物理機的 80 端口:容器實例的 80 端口 ,把容器中的 80 端口映射到物理機上的 80 端口
另外一種啓動方式
[root@Docker ~]# cd /docker-build
[root@Docker docker-build]# docker run -d -p 80:80 centos:httpd /bin/bash -c start.sh
在物理機上查看容易狀態
[root@Docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf183879c15b centos:httpd "/bin/bash -c /usr/l…" 24 seconds ago Up 23 seconds 0.0.0.0:80->80/tcp happy_mahavira
查看物理機上開啓的 80 代理端口
[root@Docker ~]# netstat -pantu | grep 80
tcp6 0 0 :::80 :::* LISTEN 10870/docker-proxy
udp6 0 0 fe80::c43:91ff:fe1a:123 :::* 7829/ntpd
udp6 0 0 fe80::42:deff:fe9c::123 :::* 7829/ntpd
udp6 0 0 fe80::250:56ff:fe35:123 :::* 7829/ntpd
測試
在瀏覽器輸入 http://192.168.10.7
總結
以上就是 Docker Image 的發佈和 Container 端口映射的操做過程,但願能幫助到你們。