Score:0

Not getting nginx and gunicorn running in Docker container

es flag

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.

Score:1
jp flag

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.

es flag
Thanks for your reply. What's the best practice to start these daemons/processes?
jp flag
The best practice is to start these daemons/processes in the foreground. Use a separate container for each service/process.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.