#下載nginx鏡像
~]# docker pull nginx:1.12.2
#打標簽
~]# docker tag 4037a5562b03 lihanbing/nginx:v1.12.2
#端口映射
~]# docker run --rm --name mynginx -d -p81:80 lihanbing/nginx:v1.12.2
1744d5461d798e12170d4fe87c5770717b63204f151d95f79953686e277e9ad1
~]# netstat -lntp | grep 81
tcp6 0 0 :::81 :::* LISTEN 17090/docker-proxy
~]# curl 127.0.0.1:81
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a >nginx.org</a>.<br/>
Commercial support is available at
<a >nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
#掛載數(shù)據(jù)卷
~]# mkdir html
~]# cd html/
html]# wget www.baidu.com -O index.html
--2020-04-05 22:29:18-- http://www.baidu.com/
正在解析主機 www.baidu.com (www.baidu.com)... 39.156.66.14, 39.156.66.18
正在連接 www.baidu.com (www.baidu.com)|39.156.66.14|:80... 已連接。
已發(fā)出 HTTP 請求,正在等待回應... 200 OK
長度:2381 (2.3K) [text/html]
正在保存至: “index.html”
100%[============================================================================================>] 2,381 --.-K/s 用時 0s
2020-04-05 22:29:18 (328 MB/s) - 已保存 “index.html” [2381/2381])
html]# docker run -d --rm --name nginx_with_baidu -p82:80 -v /root/html:/usr/share/nginx/html lihanbing/nginx:v1.12.2
9234ae478a66e3ec1448af243f765e235c748e8f387ea167d58272b2b0c7c511
html]# docker exec -it 9234ae478a66 /bin/bash
/# cd /usr/share/nginx/html/
root@9234ae478a66:/usr/share/nginx/html# ls
index.html
#檢查容器運行情況
~]# docker inspect 9234ae478a66 | grep share
"/root/html:/usr/share/nginx/html"
"Destination": "/usr/share/nginx/html",
#傳遞環(huán)境變量
~]# docker run --rm -e E_OPS=abcdefg lihanbing/alpine:v3.10.3 printenv
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=42f64853747f
E_OPS=abcdefg
HOME=/root
#傳遞多個環(huán)境變量
~]# docker run --rm -e E_OPS=abcdefg -e C_OPS=123 lihanbing/alpine:v3.10.3 printenv
#容器內(nèi)安裝軟件
~]# docker exec -it nginx_with_baidu /bin/bash
/# curl
bash: curl: command not found
root@9234ae478a66:/# cat /etc/issue
Debian GNU/Linux 9 \n \l
/# tee /etc/apt/sources.list << EOF
deb http://mirrors.163.com/debian/ jessie main non-free contrib
deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib
EOF
/# apt-get update && apt-get install curl -y
#固化鏡像
~]# docker commit 9234ae478a66 lihanbing/nginx:curl
sha256:e57f211297903aa6504ec936b9cf640feb0ca99a92f59da2cb61baf1d65234cc
#推送鏡像到hub.docker.com
~]# docker push lihanbing/nginx:curl
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。