docker run -p 容器外端口:容器內(nèi)端口
發(fā)布一個nginx應(yīng)用
-----
[root@docker ~]# docker images #查看鏡像
REPOSITORY TAG IMAGE ID CREATED SIZE
myalpine latest_with_hello.txt 3ce9b8b899ba 17 hours ago 5.59MB
nginx latest f7bb5701a33c 10 days ago 126MB
alpine latest cc0abc535e36 2 weeks ago 5.59MB
zhoumingkang/alpine v3.10.3 cc0abc535e36 2 weeks ago 5.59MB
alpine 3.9.4 055936d39205 8 months ago 5.53MB
hello-world latest fce289e99eb9 12 months ago 1.84kB
[root@docker ~]# docker run --rm -d --name mynginx -p80:80 nginx:latest #運行容器
12f98b8cbbc8c918dce442c085b6e6a8e40df86a41d7016c8c8bfb1395b5bc90
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
12f98b8cbbc8 nginx:latest "nginx -g 'daemon ofΒ 6 seconds ago Up 4 seconds 0.0.0.0:80->80/tcp mynginx
[root@docker ~]# netstat -tlunp | grep 80
tcp6 0 0 :::80 :::* LISTEN 10728/docker-proxy
docker run -v 容器外目錄:容器內(nèi)目錄
把當前主機/root/html目錄掛載到容器內(nèi)/usr/share/nginx/html
-----
[root@docker html]# docker run --rm -d --name mynginx1 -p81:80 -v/root/html:/usr/share/nginx/html nginx:latest #影射端口并掛載本地目錄到容器內(nèi)
5b3ef0ed66d8927c6e3e502c8cc652243e81e94922f8b6310fa26bf9cb0ab8c1
[root@docker html]# netstat -tlunp | grep 81
tcp6 0 0 :::81 :::* LISTEN 11587/docker-proxy
[root@docker html]# docker ps | grep mynginx1
5b3ef0ed66d8 nginx:latest "nginx -g 'daemon of…" 6 minutes ago Up 6 minutes 0.0.0.0:81->80/tcp mynginx1
[root@docker html]# docker exec -ti 5b3ef0ed66d8 /bin/sh #進入該容器
# ls /usr/share/nginx/html #查看宿主機目錄是否掛載上去
index.html
docker run -e 變量名=變量值
把系統(tǒng)變量增加一段mingkang_env=mingkang_test
-----
[root@docker html]# docker run -ti --rm --name myalpine -e mingkang_env=mingkang_test alpine:latest /bin/sh
/ # env
HOSTNAME=b6dad57f224f
SHLVL=1
HOME=/root
mingkang_env=mingkang_test #增加的環(huán)境變量
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
備注:多環(huán)境變量時,多加-e
在當前NGINX容器里,安裝curl工具命令
-----
[root@docker html]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b3ef0ed66d8 nginx:latest "nginx -g 'daemon of…" 33 minutes ago Up 33 minutes 0.0.0.0:81->80/tcp mynginx1
[root@docker html]# docker exec -ti mynginx1 /bin/bash
root@5b3ef0ed66d8:/# apt-get update
root@5b3ef0ed66d8:/# apt-get install -y curl #容器里安裝工具
root@5b3ef0ed66d8:/# which curl
/usr/bin/curl
[root@docker html]# docker commit -p mynginx1 zhoumingkang/nginx:curl #生成本地鏡像
sha256:d1b81c37853c29e7069b5127e19e28f0eb964f7a5720a81880a1f3ecda4c88b4
[root@docker html]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zhoumingkang/nginx curl d1b81c37853c 6 seconds ago 152MB
myalpine latest_with_hello.txt 3ce9b8b899ba 24 hours ago 5.59MB
nginx latest f7bb5701a33c 10 days ago 126MB
alpine latest cc0abc535e36 2 weeks ago 5.59MB
zhoumingkang/alpine v3.10.3 cc0abc535e36 2 weeks ago 5.59MB
alpine 3.9.4 055936d39205 8 months ago 5.53MB
hello-world latest fce289e99eb9 12 months ago 1.84kB
[root@docker html]# docker push zhoumingkang/nginx:curl #推送鏡像到遠端
The push refers to repository [docker.io/zhoumingkang/nginx]
edb65c87d072: Pushed
75248c0d5438: Mounted from library/nginx
49434cc20e95: Mounted from library/nginx
556c5fb0d91b: Mounted from library/nginx
curl: digest: sha256:15a6e2920bc27d9a46a5025b938d54451bac6e499ae51c65cc812d9a193f8f59 size: 1160
[root@docker html]#
網(wǎng)頁題目:Docker之容器重要日常操作
網(wǎng)址分享:http://www.rwnh.cn/article30/gdgoso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標簽優(yōu)化、靜態(tài)網(wǎng)站、微信公眾號、動態(tài)網(wǎng)站、小程序開發(fā)、品牌網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)