nginx dockerfile 配置nginx启动

CMD ["nginx"]

######### 容器启动不了 ########

[hadoop@hadoop03 fastdfs-docker]$  sudo docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS                     PORTS     NAMES
d0b4d37f1121   9d24dd437383   "/usr/local/bin/run.…"   5 seconds ago   Exited (0) 3 seconds ago             confident_moser
[hadoop@hadoop03 fastdfs-docker]$

If you add a custom CMD in the Dockerfile, be sure to include -g daemon off; in the CMD in order for nginx to stay in the foreground, so that Docker can track the process properly (otherwise your container will stop immediately after starting)!

dockerfile 文件添加

RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf
[hadoop@hadoop03 fastdfs-docker]$  sudo docker exec -it  f0 bash
[root@f049b8bd8e89 /]# ps aux | grep nginx
root          1  0.1  0.0  28104  1724 ?        Ss   07:07   0:00 nginx: master process nginx
nobody        7  0.0  0.0  28680  1780 ?        S    07:07   0:00 nginx: worker process
root         28  0.0  0.0   9196   684 pts/0    S+   07:08   0:00 grep --color=auto nginx
[root@f049b8bd8e89 /]# curl localhost:80
<!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>
[root@f049b8bd8e89 /]#

参考:https://www.cnblogs.com/luguojun/p/14294659.html

更多推荐