Unable to bring up the container using custom shell script as docker entrypoint

0 votes

I’m trying to use docker-compose to bring up a container. As an ENTRYPOINT, that I have written a simple bash script which is inside the container. But whenwhenever I try to bring up the container in any of the below ways:

  • docker-compose up
  • docker-compose up foo

it doesn’t complete. i.e., trying to attach to the running container, fails with:

Error response from daemon: Container xyz is restarting, wait until the container is running.

I tried playing around with putting commands in the background. That didn’t work.

my-script.sh

cmd1 &
cmd2 &&
...
cmdn &

I also tried i) with and without entrypoint: /bin/sh /usr/local/bin/my-script.sh and ii) with and without the tty: true option. No dice.

docker-compose.yml

version: '2'
services:
  foo:
    build:
      context: .
      dockerfile: Dockerfile.foo
    ...
    tty: true
    entrypoint: /bin/sh /usr/local/bin/my-script.sh

I have also tried a manual docker build / run cycle. And (without launching /bin/sh in the ENTRYPOINT ) the run just exits.

$ docker build ... .
$ docker run -it ... 
... shell echos commands here, then exits
$

Can anyone help me with this?

Thanks.

Aug 9, 2018 in Docker by shubham
• 7,340 points
2,527 views

1 answer to this question.

0 votes
You have to put something infinite so that it will keep running your container in background,like you can tail -f application.log or anything like this so that even if you exit from your container bash it keeps running in background.

you do not need to do cmd1 & cmd2 &&...cmdn & just place one command like this touch 1.txt && tail -f 1.txt as a last step in your my-script.sh. It will keep running your container.

 One thing also you need to change is docker run -it -d -d will start container with background mode.If you want to go inside your container than docker exec -it container_name/id bash debug the issue and exit.

It will still keep your container running until you stop with docker stop container_id/nameHope this help.

I hope it will resolve your query.
answered Aug 9, 2018 by Damon Salvatore
• 5,980 points

Related Questions In Docker

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,610 points
3,274 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,497 views
0 votes
1 answer

Docker, how to get container information from within the container?

I've found out that the container id ...READ MORE

answered Jul 31, 2018 in Docker by Kalgi
• 52,360 points
781 views
0 votes
1 answer

Docker error cannot delete docker container, conflict: unable to remove repository reference

First, remove the container names $ sudo docker ...READ MORE

answered Jul 31, 2018 in Docker by Kalgi
• 52,360 points
5,066 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,090 points
2,474 views
+1 vote
2 answers

How do I copy a file from docker container to host?

Here is a way which you can ...READ MORE

answered Aug 28, 2018 in Docker by Damon Salvatore
• 5,980 points
28,212 views
0 votes
3 answers

What is the difference between a Docker image and a container?

Images are read-only templates that contain a ...READ MORE

answered Aug 10, 2020 in Docker by Vishal
• 260 points
6,166 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