0

I am a student, and I am currently trying to deploy my Django application on Docker Ubuntu using Nginx and Gunicorn. However, when I restart the container, both Nginx and Gunicorn are also turned off. I have to use the command "docker attach " to enter the container and run the commands service nginx start and systemctl start gunicorn. Is there any way to automatically start Nginx and Gunicorn when the container is restarted? Thank you sincerely. [This is the configuration file.](https://i.stack.imgur.com/HC7Ol.png)

I have tried writing a start.sh file like this:

#!/bin/bash

# Start Nginx
service nginx start

# Start Gunicorn
systemctl start gunicorn

exec "$@"

and Dockerfile

FROM my_image

COPY start.sh /start.sh
RUN chmod +x /start.sh


EXPOSE 80

CMD ["/start.sh"]
  • Welcome to Stackoverflow! This question is duplicate of following question: https://serverfault.com/questions/685697/multiple-commands-in-docker-cmd-directive – Micheal Choudhary May 24 '23 at 10:16
  • Commands like `service` and `systemctl` don't really work in Docker. Can you split this into two separate containers instead? (I'm not clear that Nginx will accept the PNG-format configuration, and you might [edit] the question to include it in plain text instead.) – David Maze May 24 '23 at 10:20
  • [Why can't I use Docker CMD multiple times to run multiple services?](https://stackoverflow.com/questions/23692470/why-cant-i-use-docker-cmd-multiple-times-to-run-multiple-services) probably gives the clearest set of common answers of the various related questions on Stack Overflow, but it's usually considered a best practice (and is simpler) to run only one program in a container, and to use multiple single-process containers together. – David Maze May 24 '23 at 10:25

0 Answers0