3

I created a docker image based on nginx and included the config in the image it self.

ThenI start the container (docker run -p 2000:80 nginx_be:0.1). When I don't check for running containers with docker ps there are none.

What am I missing?

My Dockerfile

FROM nginx
ADD /conf/nginx.conf /etc/nginx/nginx.conf:ro
WORKDIR /etc/nginx
EXPOSE 80
CMD ["nginx", "-c", "/etc/nginx/nginx.conf"]
Boas Enkler
  • 12,264
  • 16
  • 69
  • 143

1 Answers1

4

The latest nginx Dockerfile does end with:

CMD ["nginx", "-g", "daemon off;"]

You should do the same in order to avoid nginx launching as a daemon (background), which would make the container stop immediately (because of the lack of a foreground process).
See also "How to Keep Docker Container Running After Starting Services?".

You can also see this docker run command which override your Dockerfile CMD:

docker run -t -d --name my-nginx nginx /usr/sbin/nginx -g "daemon off;"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    @BoasEnkler Yes, I have also edited the answer to highlight a way to test that command without editing the Dockerfile/building your image first. – VonC Jun 13 '17 at 06:31