I create an image using the following Docker file:

FROM ubuntu:16.10 RUN apt-get update && apt-get install -y nginx python3-pip RUN mkdir -p /home/app/ COPY ./nginx.conf /etc/nginx/ COPY . /home/app/ WORKDIR /home/app/ RUN pip3 install gunicorn RUN pip3 install -v -r requirements.txt RUN service nginx restart EXPOSE 80 CMD ["gunicorn", "go2change.wsgi:application"] 

When creating a container, nginx does not show signs of life, although the process is running.

If you do the docker exec and dial inside:

 service nginx restart 

everything starts working as it should.

What could be the problem?

    1 answer 1

    the problem, apparently, is in the misunderstanding of what lxc cgroups is used for ( docker now does not use lxc ) in general and the “wrapper” around lxc cgroups called docker in particular.

    and they serve to run inside an isolated environment of a single process (when this process terminates, the environment is destroyed).

    and if you need to run more processes in the same environment (in your case, nginx and python ), then you need to run a kind of “super” process that will start all the rest you need.

    most often , the supervisor program is used as such a “super” process (a package with this name is present in the repositories of popular distributions). although, of course, it is possible (and also often occurs) to write a mini-script “on the knee”, which will launch the processes you need and will wait for their completion (if it completes, see the second paragraph above).


    addition about run and cmd

    run directives in the dockerfile file are executed during the creation of the image ( image ), but not during the launch of the isolated environment (in short: the container).

    when the container is started, the cmd directive is executed.

    • Only there nginx and Python, I do not observe Ruby symptoms :) - D-side
    • @ D-side, for sure. I somehow thought that gunicorn was written in ruby. corrected. - aleksandr barakin
    • Almost. Unicorn on Ruby. Gunicorn, roughly, its counterpart in the world of Python. - D-side
    • Thanks, I will try) - Xamber