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 section 💬.
My goal with this blog is mainly to create helpful content for
Connect with me here LinkedIn • Twitter • Instagram • 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 section 💬.
My goal with this blog is mainly to create helpful content for
Java
and Javascript
web devs, if you want to discuss a specific topic related to the programming world, you can reach me on my social platforms. Connect with me here LinkedIn • Twitter • Instagram • GitHub or Medium