English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
docker exec :Execute commands in running containers
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
OPTIONS description:
-d :Detached mode: Run in the background
-i :Keep STDIN open even if not attached
-t :Allocate a pseudo terminal
Execute the script inside the container mynginx in interactive mode /root/w3codebox.sh script:
w3codebox@w3codebox:~$ docker exec -it mynginx /bin/sh /root/w3codebox.sh http://www.oldtoolbag.com/
Open an interactive terminal in the container mynginx:
w3codebox@w3codebox:~$ docker exec -i -t mynginx /bin/bash root@b1a0703e41e7:/#
You can also use docker ps -Use the 'a' command to view containers that are already running, and then enter the container using the container ID.
View the container IDs of containers that are already running:
# docker ps -a ... 9df70f9a0714 openjdk/usercode/script.sh... ...
The first column's 9df70f9a0714 This is the container ID.
Execute bash for the specified container using the exec command:
# docker exec -it 9df70f9a0714 /bin/bash