#下载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 href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
#挂载数据卷
~]# 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... 已连接。
已发出 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",
#传递环境变量
~]# 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
#传递多个环境变量
~]# docker run --rm -e E_OPS=abcdefg -e C_OPS=123 lihanbing/alpine:v3.10.3 printenv
#容器内安装软件
~]# 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
网友评论