1.显示所有的容器,包括未运行的
docker ps -a
2.启动一个已停止的容器
docker start 容器id或name(可通过1中的命令查看) docke restart 容器id或name 用于重启容器
3.停止一个容器
docker stop 容器id
4.强制删除一个运行中的容器
docker rm -f 容器id
5.查看容器内部的标准输出
docker logs [ID或者名字]
6.批量删除未使用的容器
docker container prune
[root@ipha-dev71-1 chenjl]# docker pull training/webapp [root@ipha-dev71-1 chenjl]# docker run -d -P training/webapp python app.py [root@ipha-dev71-1 chenjl]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f48e38ee81a9 training/webapp "python app.py" 15 seconds ago Up 10 seconds 0.0.0.0:32768->5000/tcp sweet_brown [root@ipha-dev71-1 chenjl]# docker run -d -p 5000:5000 training/webapp python app.py # 如果是-itd的话是指在后台运行,不会进入容器(-i 交互式操作 -t 终端),
69fbb799c3d5bf4526cbcca9505519ec18c0bdb010301c533c779e47f351e96a [root@ipha-dev71-1 chenjl]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 69fbb799c3d5 training/webapp "python app.py" 3 seconds ago Up 2 seconds 0.0.0.0:5000->5000/tcp magical_khorana f48e38ee81a9 training/webapp "python app.py" 55 minutes ago Up 55 minutes 0.0.0.0:32768->5000/tcp sweet_brown [root@ipha-dev71-1 chenjl]# docker logs -f 69fbb799c3d5 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) ^C [root@ipha-dev71-1 chenjl]# docker top magical_khorana UID PID PPID C STIME TTY TIME CMD root 104711 104694 0 22:53 ? 00:00:00 python app.py [root@ipha-dev71-1 chenjl]# docker inspect magical_khorana [ { "Id": "69fbb799c3d5bf4526cbcca9505519ec18c0bdb010301c533c779e47f351e96a", "Created": "2019-09-16T14:53:21.107783511Z", "Path": "python", "Args": [ "app.py" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, ... [root@ipha-dev71-1 chenjl]# docker stop magical_khorana magical_khorana [root@ipha-dev71-1 chenjl]# docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 69fbb799c3d5 training/webapp "python app.py" 4 minutes ago Exited (137) 26 seconds ago magical_khorana [root@ipha-dev71-1 chenjl]# docker rm magical_khorana magical_khorana
进入与退出docker容器
[root@ipha-dev71-1 12306]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f48e38ee81a9 training/webapp "python app.py" 2 days ago Up 2 days 0.0.0.0:32768->5000/tcp sweet_brown [root@ipha-dev71-1 12306]# docker exec -it f48e38ee81a9 /bin/bash # 进入docker容器 root@f48e38ee81a9:/opt/webapp# ll total 20 drwxr-xr-x 2 root root 94 May 15 2015 ./ drwxr-xr-x 1 root root 20 May 15 2015 ../ -rw-r--r-- 1 root root 11 May 15 2015 .gitignore -rw-r--r-- 1 root root 19 May 15 2015 Procfile -rw-r--r-- 1 root root 347 May 15 2015 app.py -rw-r--r-- 1 root root 41 May 15 2015 requirements.txt -rw-r--r-- 1 root root 285 May 15 2015 tests.py root@f48e38ee81a9:/opt/webapp# pwd /opt/webapp root@f48e38ee81a9:/opt/webapp# exit # 退出docker容器 exit