To start an interactive bash shell in a Docker container, you can use the docker exec command that allows you to execute commands in running containers.
$ docker exec -it <container> /bin/bash
Where container
is either the name or the ID of a Docker container that can be obtained using the docker ps
command.
You may need to run a single command in a running Docker container. Instead of starting an interactive shell session, you can use the -c
flag (short for command ) of the bash utility which will execute the specified command.
$ docker exec <container> /bin/bash -c '<command>'
Where:
container
is either the name or the identifier of a container.command
is the command you want to run in the container.
Here is a simple example for a single command execution (in a running container).
$ docker exec 14c5r /bin/bash -c 'ls -la'
Hope this short post helped.
Author : Kevin Kouomeu
I hope you enjoyed reading this, and I'm curious to hear if this tutorial helped you. Please let me know your thoughts below in the comments. Don't forget to subscribe to my newsletter to avoid missing my upcoming blog posts.
You can also find me here LinkedIn • Twitter • GitHub or Medium
I hope you enjoyed reading this, and I'm curious to hear if this tutorial helped you. Please let me know your thoughts below in the comments. Don't forget to subscribe to my newsletter to avoid missing my upcoming blog posts.
You can also find me here LinkedIn • Twitter • GitHub or Medium