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
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.
For containers that are stopped, you can also start the container using the Docker start command and then run the Docker exec command.
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!
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With