How to keep Docker container running after starting services

0 votes

Although I've read many instructions that appear to do what I'm trying to do, for some reason my Docker containers keep failing. In essence, I'm configuring a Docker container to house a web server and a few daemons. In my Dockerfile, I run a bash script called run-all.sh through CMD to complete the remaining steps. run-all. Sh appears as follows:

service supervisor start
service nginx start

And I start it inside of my Dockerfile as follows:

CMD ["sh", "/root/credentialize_and_run.sh"]

When I run things manually (by connecting to the image with -i -t /bin/bash), I can see that all of the services start up properly. When I run the image, however, it exits after starting up my processes. According to my understanding, for the processes to continue operating indefinitely, the container must remain active. But when I use docker ps -a, I observe:

➜  docker_test  docker ps -a
CONTAINER ID        IMAGE                            COMMAND                CREATED             STATUS                      PORTS               NAMES
c7706edc4189        some_name/some_repo:blah   "sh /root/run-all.sh   8 minutes ago       Exited (0) 8 minutes ago                        grave_jones

How come? Why is that happening? What's the proper technique to prevent my bash script from exiting? I know I could just add a while loop to the end of it to keep it going.

Dec 13, 2022 in Docker by Edureka
• 12,880 points
165 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Docker

0 votes
1 answer

How to continue running a docker container which is already exited?

Restart an existing container after you exited ...READ MORE

answered Jul 19, 2018 in Docker by Sophie may
• 10,590 points
1,803 views
0 votes
2 answers

How to edit file after I shell to a docker container?

You can even install it using a ...READ MORE

answered Apr 23, 2019 in Docker by Ashish
17,032 views
+1 vote
7 answers

How to connect to a Docker container running mysql on Windows 10?

Avoid using bind_address in your my.cnf file. I don't ...READ MORE

answered Apr 25, 2019 in Docker by Haseeb
11,358 views
+2 votes
1 answer

How to link one running container with other running container in docker.

Hi @Yuvraj! Yes, this is possible. You can ...READ MORE

answered Dec 16, 2019 in Docker by Kalgi
• 52,350 points
1,049 views
+4 votes
4 answers

How To Access a Service on Host From a Docker Container?

Adding to kalgi's answer, You can also ...READ MORE

answered Oct 16, 2018 in Docker by lina
• 8,220 points

edited Oct 16, 2018 by lina 29,025 views
0 votes
1 answer

How to run a docker command from inside the container?

You must have come across the /var/run/docker.sock file, ...READ MORE

answered Jun 28, 2018 in Docker by Sophie may
• 10,590 points
2,810 views
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,100 points
1,994 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP