0

I have a small Gunicorn service. This is my Dockerfile for it:

FROM ubuntu:16.04

RUN apt-get clean && apt-get update && apt-get install -y locales
RUN locale-gen en_US.UTF-8
RUN update-locale LANG=en_US.UTF-8 LC_MESSAGES=POSIX

RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get install -y python-pip \
&& mkdir /app


ADD . app
WORKDIR /app

RUN pip install -r requirements.txt

CMD ["/usr/local/bin/gunicorn", "--config", "/app/gunicorn.py", "myrun:app", "&&", "tail", "-f", "/dev/null"]

The problem is I can't hold the container as the active process. I run it so: docker run --name pypypy -td -p 8187:8081 pytest.

What do I do wrong ? I read some posts at stackoverflow. But it doesn't work for me and I don't know why.

faoxis
  • 1,912
  • 5
  • 16
  • 31
  • what's the container output? – whites11 Sep 05 '17 at 08:30
  • @whites11 just one string with id. Something like `bc95a716f2309b1ff0624af28efce442eb89e0c21e88202a1059f8bd4b0a3762`. – faoxis Sep 05 '17 at 08:32
  • yeah, thats the container ID. try running the image without the "-d" flag to get the standard output – whites11 Sep 05 '17 at 08:33
  • 3
    I'm not sure but I doubt that the `CMD` is passed to a shell, so the `&&` will not be evaluated as you expect it but instead will be passed verbatim as argument to `gunicorn` which will probably be surprised and thus terminate quickly. – Alfe Sep 05 '17 at 09:15
  • Try the SHELL form of CMD rather than EXEC "CMD /usr/local/bin/gunicorn --config /app/gunicorn.py myrun:app && tail -f /dev/null" – Sreeni Sep 05 '17 at 13:31

1 Answers1

0

Did you decide to add the && tail -f /dev/null or is that copied from another Dockerfile example? My assumption is that this is an attempt to keep tail as the active process, waiting forever on the null device after starting gunicorn in the background?

Anyway, I'm pretty sure that is an unnecessary addition if your purpose is just to have a single-process container with gunicorn running inside. For example, this blog post on the topic seems to show gunicorn running just fine as a non-daemon within a container. You might be able to get the && tail.. method working, but I think it is actually cleaner to just have the gunicorn process running, and maybe for more "Docker best practice" alignment, use the logging setup from that blog post so that docker logs work properly with your containerized gunicorn process.

Phil E
  • 1,840
  • 14
  • 19