Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker exec command doesn't return after completing execution

Tags:

docker

exec

I started a docker container based on an image which has a file "run.sh" in it. Within a shell script, i use docker exec as shown below

docker exec <container-id> sh /test.sh

test.sh completes execution but docker exec does not return until i press ctrl+C. As a result, my shell script never ends. Any pointers to what might be causing this.

like image 463
pc70 Avatar asked Jun 16 '16 03:06

pc70


People also ask

How do I keep docker containers running after exit?

Dockerfile Command to Keep the Container Running Method 1: You can use the -t (pseudo-tty) docker parameter to keep the container running. Method 2: You can run the container directly passing the tail command via arguments as shown below. Method 3: Another method is to execute a sleep command to infinity.

Can the Docker EXEC command be run on stopped containers?

For containers that are stopped, you can also start the container using the Docker start command and then run the Docker exec command.

What is the difference between docker run and exec?

Docker Run vs Docker Exec! This is a fairly common question – but has a simple answer! In short, docker run is the command you use to create a new container from an image, whilst docker exec lets you run commands on an already running container! Easy!

How can I run a docker EXEC command inside a docker container?

Running Commands in an Alternate Directory in a Docker Container. To run a command in a certain directory of your container, use the --workdir flag to specify the directory: docker exec --workdir /tmp container-name pwd.


1 Answers

I could get it working with adding the -it parameters:

docker exec -it <container-id> sh /test.sh

like image 198
Matthias Lohr Avatar answered Nov 15 '22 05:11

Matthias Lohr