-it,交互方式启动
–name nginx_test,指定新容器的名称是nginx_test
-h docker-nginx,指定新容器的主机名是docker-nginx
-p 8001:81 -p 8000:80,指定宿主机与docker容器的端口映射,宿主机的8001对应docker容器的81,宿主机的8000对应docker容器的80
-v /home/linuxidc/docker/nginx_web/:/home/visual/nginx_web/,指定宿主机与docker容器的文件映射,宿主机的/home/linuxidc/docker/nginx_web/ 对应docker容器的 /home/visual/nginx_web/
learn/nginx:v2,指定启动容器对应的镜像是learn/nginx:v2,可以是镜像ID
/bin/sh /etc/rc.local,指定容器启动后,执行shell脚本是/etc/rc.local
查看docker容器,容器nginx_test处于up状态,说明启动正常
linuxidc@linuxidc:~/docker/nginx_web$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cbbbe7a5d47a learn/nginx:v2 "/bin/sh /etc/rc.l..." 25 minutes ago Up 24 minutes 0.0.0.0:8000->80/tcp, 0.0.0.0:8001->81/tcp nginx_test
966bd52b72da ubuntu "/bin/sh -c 'while..." 42 hours ago Exited (137) 40 hours ago stupefied_knuth
00f561d97811 ubuntu "/bin/echo hello w..." 42 hours ago Exited (0) 42 hours ago nifty_mcnulty
93a1b9d39683 ubuntu "bash" 43 hours ago Exited (0) About an hour ago zealous_noether
abdc084f9821 hello-world "/hello" 43 hours ago Exited (0) 20 hours ago sleepy_clarke
5、测试docker_nginx是否正常
通过浏览器测试8001端口
通过浏览器测试8000端口
修改宿主机的文件,并测试8001端口
修改宿主机的/home/linuxidc/docker/nginx_web/index.html文件
linuxidc@linuxidc:~/docker/nginx_web$ vi index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx! I am in docker!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx! I am in Docker!</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="https://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="https://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
通过浏览器测试8001端口,发现“Welcome to nginx! I am in docker!”,说明内容已经修改,使用docker做为web服务器的功能已经OK
更多Docker相关教程见以下内容: