DevOpsDockerDockersHow to

Docker exec command

If you want to get access to container, but don’t want to attach to the executing command.
You can do this by using the container exec command.
you can execute command in running container, This command is often used to create an interactive session with an already-running container or to execute a single command within the container.
The command looks like this:

# start an nginx container detached
docker container run --detach --name web-server1 -p 80:80 nginx
# see that the container is currently running
docker container ls
# execute other commands in the running container
# Usage: docker container exec [OPTIONS] CONTAINER COMMAND [ARG...] docker container exec -it web-server1 bash
docker container exec web-server1 cat /etc/debian_version
# confirm that the container is still running
docker container ls

When you finished the exec command, you exit the bash shell, or the file contents have been displaced, then it exits back to the terminal session leaving the container running detached:

Docker Container exec command

Related Articles

Leave a Reply

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

FXbht fZr9 TD

Please type the text above:

Check Also