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
• 6,890 points
72 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,510 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
• 9,870 points
413 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 in Docker by Ashish
3,436 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
• 42,510 points
69 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
• 42,510 points
450 views
0 votes
1 answer
0 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
• 56,940 points
228 views
0 votes
1 answer

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

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

answered Aug 27, 2018 in Docker by Damon Salvatore
• 5,510 points
3,886 views
0 votes
2 answers

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

Here is very basic explanation for image ...READ MORE

answered Sep 4, 2018 in Docker by Damon Salvatore
• 5,510 points
980 views