When using Docker, sometimes I want to connect to its containers using interactive commands.
In this article, I will show you how to do that with a simple shell command.
The command you need is:
$ docker exec -it <DOCKER_CONTAINER_NAME> bash
This command runs the bash
command inside the container and gives you access to the bash shell of it.
When you enter this command, you will see the bash prompt like this:
bash-5.1$
This command uses the exec
command with two options: -it
. These options respectively enable an interactive shell and allocate a TTY.
Option | Description |
---|---|
-i, --interactive | connect to STDIN of the container |
-t, --tty | Allocate a pseudo terminal |
If you want to edit the container's files frequently, it's better to use Visual Studio Code and Docker extension for Visual Studio Code
References
Top comments (0)