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 and 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 or opinions below in the comments section. You can have more of my content by following me on LinkedIn • 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 or opinions below in the comments section. You can have more of my content by following me on LinkedIn • GitHub or Medium