What is the use of docker exec command?

DOCKER EXEC command is used to run a second command in an already running docker container.

In Docker, EXEC command is used to run a second command in an already running docker container.

When a docker container is started by means of START or RUN commands, we optionally specify a startup command which is the first command that is executed as soon as the container starts up.

But there could be scenarios where we would want to run another command on the already running container, or we may want to do a shell into the container (for debug purpose e.g)

In such cases we use the docker exec command along with the command to run.

docker exec -it c669abe2068a bash

In the above example, the EXEC command runs a “bash” command on the running container resulting in opening a bash terminal.

The flags i and t along with the command represent “input” and output to terminal respectively.


Buy Me A Coffee

Found this article helpful? Please consider supporting!

Ram
Ram

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity. You can connect with me on Medium, Twitter or LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *