nginx的内部没有泊坞
问题描述:
开始这里是我的Dockerfile:nginx的内部没有泊坞
FROM ubuntu:14.04.4
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN add-apt-repository ppa:nginx/stable
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y nginx
ADD configurations/nginx.conf /etc/nginx/nginx.conf
ADD configurations/app.conf /etc/nginx/sites-available/default.conf
RUN ln -sf /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf
RUN chown -Rf www-data.www-data /var/www/
ADD scripts/start.sh /start.sh
RUN chmod 755 /start.sh
EXPOSE 443
EXPOSE 80
CMD ["/bin/bash", "/start.sh"]
的start.sh脚本:
cat scripts/start.sh
service nginx start
echo "test" > /tmp/test
当我登录到容器:
docker exec --interactive --tty my_container bash
既不测试文件存在,也不运行nginx。 nginx日志中没有错误。
答
尝试
RUN /etc/init.d/nginx start
答
最好的做法是在前台,而不是作为服务运行的过程。
删除start.sh文件,改变CMD到:
CMD ["nginx", "-g", "daemon off;"]
你可以得到一个更好的主意阅读官方nginx的dockerfile:https://github.com/nginxinc/docker-nginx/blob/master/stable/jessie/Dockerfile
这可能是该码头工人希望您的应用程序开始运行并且永远不会像在前台进程中那样返回。如果你的启动脚本返回,那么Docker退出。所以试试上面链接的解决方案。 – spokeadoke
您可以像使用示例一样使用官方图像https://github.com/nginxinc/docker-nginx/blob/19799fa644461ed6c5ea07c0bc0ea0cc277c2d77/mainline/jessie/Dockerfile – ashatrov
当您使用'exec'登录到您的容器并尝试运行时会发生什么?/bin/bash/start.sh'。它会给你在尝试在入口处运行start.sh时可能发生的确切故障。 – Rahul