0

I am new to Docker and trying my best to figure out every bit, but seriously struggle on starting gunicorn and nginx with my Dockerfile. Whenever I add the last four lines, the container won't boot and also fails with no error message at all.

FROM python:3.9-buster EXPOSE 80 RUN apt update RUN apt upgrade RUN apt install nginx python3 python3-pip git swig python3-dev build-essential libmagic-dev -y RUN apt install ffmpeg -y RUN mkdir /opt/xxx RUN git clone https://xxx:[email protected]/xxx/backend.git /opt/xxx/ RUN mkdir /root/d12f RUN python3 -m pip install --upgrade pip COPY .env /opt/xxx/xxx/.env RUN pip3 install -r /opt/xxx/requirements.txt RUN pip3 install gunicorn RUN git clone https://xxx:[email protected]/xxx/configs.git /root/configs/ RUN cp /root/configs/nginx/default /etc/nginx/sites-available/. RUN mkdir /var/log/celery/ CMD /usr/sbin/nginx -c /etc/nginx/nginx.conf CMD /usr/local/bin/celery -A xxx --workdir /opt/xxx worker --loglevel=INFO -P prefork & CMD /usr/local/bin/celery -A xxx --workdir /opt/xxx beat --schedule=/tmp/celerybeat-schedule --loglevel=INFO CMD /usr/bin/gunicorn --chdir /opt/xxx --conf xxx:gunicorn_conf xxx:wsgi 

The build works as expected but running with docker run -p 80:80 xxx:latest is not.

1 Answer 1

1

Dockerfile isn't a shell script. There could be only one CMD instruction per Dockerfile (reference). Forking daemons like nginx which switch to the background by default will cause a container to terminate immediately.

2
  • Thanks for your reply. What's the best practice to start these daemons/processes? Commented Feb 3, 2022 at 18:36
  • 1
    The best practice is to start these daemons/processes in the foreground. Use a separate container for each service/process. Commented Feb 3, 2022 at 18:42

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.