Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker container hangs on exec command

Tags:

docker

Trying to execute shell commands in the docker container from localhost and inside the container ,

  docker exec -i <container-id> sh -c "ls -l"

also tried docker exec -ti <container-id> sh -c "ls -l"

it lists the output and keeps on hanging in the terminal .

Executed the above command by login in to the container It lists the output and when i type exit command , it starts hanging

Server Free RAM : 3GB

docker logs --details <container-id> 

returns empty output

like image 792
soundararajan.c Avatar asked Aug 09 '18 07:08

soundararajan.c


People also ask

What does exec command do in Docker?

The docker exec command runs a new command in a running container. The command started using docker exec only runs while the container's primary process ( PID 1 ) is running, and it is not restarted if the container is restarted. COMMAND will run in the default directory of the container.

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 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!

How would you describe a Docker container?

A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.


1 Answers

You need to allocate a pseudo-TTY with the -t option along with interactive or -i option. Try this:

$ docker exec -ti <container-id> sh -c "ls -l"
like image 135
KarateKid Avatar answered Sep 24 '22 14:09

KarateKid