[root@docker ~]# docker run -d -p 80:80 --name nginx nginx:v3
4ac935e955b1c3ac49eed68f3372f3e96a8934fd8ccf4614afa3d7c29eb96c08
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4ac935e955b1 nginx:v3 "/bin/bash" 3 seconds ago Exited (0) 2 seconds ago nginx
注:这时,你无论怎么启动这个容器,它还是一直处于exited状态。
经过各种解决,最终,终于知道问题出在了哪。 原来容器启动时,它是在后台对应着一个线程启动的,它在启动时是已经启动了,但它执行完命令后,就退出了,并没有在后台运行着,所以使用 -dit 参数让它在后台运行即可。
[root@docker ~]# docker run -dit -p 80:80 --name nginx nginx:v3
ecaafe1190447878b98dfb0198e92439db60ff7dab57a1674e0e9e7282a9c858
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ecaafe119044 nginx:v3 "/bin/bash" 3 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp nginx
然而.......
此时又出现了问题,它虽然起来了,但nginx的web网页界面访问不了,显示拒绝连接!!!!
[root@docker ~]# curl 192.168.100.22
curl: (7) Failed connect to 192.168.100.22:80; 拒绝连接
[root@docker ~]# elinks --dump 192.168.100.22
ELinks: 拒绝连接
然后,又经过问百度,FQ看谷歌,终于找到了问题的所在。原来只要使用 exec 进入到容器里启动nginx就可以了。
[root@docker ~]# docker exec -it nginx bash
[root@ecaafe119044 /]# nginx
[root@ecaafe119044 /]# exit
exit
[root@docker ~]# curl 192.168.100.22
<!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="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>
这样! Nginx镜像就构建成功了!
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx