What is the use of exec command?

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. During scenarios where we would want to run another command on the already running container, we use the 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.

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. During scenarios where we would want to run another command on the already running container, we use the 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.

Default image
Sriram Mannava

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity.

Leave a Reply