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.
🔍. Similar posts
The Simple Way to Run a Long Docker Command in Multiline
14 Jan 2025
How to Hard Reset Your Git Repository to 10 Minutes Ago
04 Sep 2024
How to Easily Generate a Java Project Using Maven Command
04 Sep 2024