Docker Community Forums

Share and learn in the Docker community.

[SOLVED] Weird issue with Nginx when building my container

(Khaliwell) #1

I am having an issue where /etc/init.d/nginx restart is apparently failing (though I don’t see evidence of that in the intermediate container or in the logs), but it works fine once I attach the container and do it manually. Here is what everything looks like:


    FROM debian:jessie
    MAINTAINER Kenyon Haliwell <>
    RUN apt-get update && \
    	apt-get -y install curl git nginx && \
	apt-get clean && \
	curl -sL | bash - && \
	apt-get -y install nodejs && \
	npm install -g bower && \
	rm -rf /var/www/html
    COPY nginx-default.conf /etc/nginx/sites-available/default
    RUN mkdir -p /var/www/frontend/code/app
    WORKDIR /var/www/frontend
    RUN /etc/init.d/nginx restart

All of it works except the last line. Here is my run command:

docker run --name mym_frontend1 -v /var/www/resources/mymv4/frontend:/var/www/frontend -p 8080:80 -dit mym_frontend

So basically, at this point if I go to my browser and go to localhost:8080 I get a ‘Connect Reset’ error. However, if I attach the container (docker attach mym_frontend1) and then do /etc/init.d/nginx restart then go back to my browser, localhost:8080 works fine.

So I am just really confused about how it doesn’t get started properly in the Dockerfile, but works just fine with I do it manually. Is there any solutions to this problem?


(Jeff Anderson) #2

It looks like you don’t have a CMD line in your Dockerfile, so the default CMD for debian:jessie will be used.

Also, the RUN /etc/init.d/nginx restart command doesn’t really do anything.

Each RUN directive tells docker to start a new container, run that command, and then commit the filesystem changes to disk once that process exits. the /etc/init.d/nginx process does something end then exits, and then the container is considered stopped. I doubt it causes any changes to be written out other than maybe a pid file, so this line really isn’t all that useful.

Take a look at the official nginx image’s Dockerfile for comparison:

(Khaliwell) #3

That fixed my issue, thanks!