It's maybe the most powerful all--around tool when working with Docker images. The exec
command allows you to run arbitrary commands inside a running container.
In opposite of the overriding the CMD
or ENTRYPOINT
, the command started using docker exec
will only run while the container's primary process (PID 1
) is running.
Also, the syntax of the exec
command is different. It's not a part of the Docker run
command, it's rather a new separate command, executed after you run your container with the docker run
. Consider the following example and run the following in one shell terminal:
docker run -it ubuntu bash --name myUbuntuBash
Then run the next command in the second shell terminal window:
dockerexec -d myUbuntuBash touch /tmp/myFile
In the preceding example, the first command fill starts the interactive bash shell from the Ubuntu container, ok that is nothing new; however...