官术网_书友最值得收藏!

Executing commands inside a container

From the output, we can see that the container status is UP. Now we can execute some commands inside the container using the docker exec command with different options:

$ docker exec -i 00f343906df3 ls -l /
total 12
drwxr-xr-x. 2 root root 4096 Feb 15 04:18 bin
drwxr-xr-x. 2 root root 6 Nov 19 15:32 boot
drwxr-xr-x. 5 root root 360 Mar 6 21:17 dev
drwxr-xr-x. 42 root root 4096 Mar 6 21:17 etc
drwxr-xr-x. 2 root root 6 Nov 19 15:32 home
...
Output truncated for brevity
...

Option -i (--interactive) allows you to run a Docker without dropping inside the container. But we can easily override this behavior and enter this container by using -i and -t (--tty) options (or just -it):

$ docker exec -it 00f343906df3 /bin/bash
root@00f343906df3:/usr/local/apache2#

We should fall into container bash CLI. From here, we can execute other general Linux commands. This trick is very useful for troubleshooting. To exit the container console, just type exit or press Ctrl D.

主站蜘蛛池模板: 师宗县| 台江县| 金华市| 青阳县| 宜兰县| 根河市| 崇明县| 崇阳县| 阳朔县| 曲麻莱县| 扶绥县| 房产| 宝兴县| 临沂市| 兰考县| 鄂温| 黔南| 怀安县| 香格里拉县| 霍城县| 新沂市| 乌鲁木齐县| 宁国市| 祁阳县| 宜良县| 青州市| 新宾| 北碚区| 英山县| 宁明县| 海晏县| 五寨县| 抚顺县| 鄂托克前旗| 南阳市| 赫章县| 广元市| 青田县| 杭锦后旗| 凌云县| 鹿邑县|