DEV Community

Cover image for Docker Exec: How to Connect to Your Containers Interactively
mich0w0h
mich0w0h

Posted on

Docker Exec: How to Connect to Your Containers Interactively

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
Enter fullscreen mode Exit fullscreen mode

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$
Enter fullscreen mode Exit fullscreen mode

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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay