容器的基本使用命令
显示所有容器
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aad183a76c03 ubuntu:self1 “/bin/bash” 3 minutes ago Up 3 minutes test03
f7dfd2fde9ac d93f3c437b14 “/bin/bash” 9 minutes ago Up 9 minutes test02
6f2a25299668 d93f3c437b14 “/bin/bash” 9 minutes ago Exited (0) 12 seconds ago test01
显示最近创建的容器
docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aad183a76c03 ubuntu:self1 “/bin/bash” About a minute ago Up About a minute test03
只显示容器pid
docker ps -q
aad183a76c03
f7dfd2fde9ac
6f2a25299668
显示docker大小
docker ps -s
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
aad183a76c03 ubuntu:self1 “/bin/bash” About a minute ago Up About a minute test03 0B (virtual 88.1MB)
f7dfd2fde9ac d93f3c437b14 “/bin/bash” 7 minutes ago Up 7 minutes test02 0B (virtual 88.1MB)
6f2a25299668 d93f3c437b14 “/bin/bash” 7 minutes ago Up 7 minutes test01 0B (virtual 88.1MB)
删除所有容器
docker rm -f $(docker ps -q -a)
aad183a76c03
f7dfd2fde9ac
查看容器详细属性
docker inspect test01
[
{
“Id”: “a9938874cd948b25dcd985191956400443d9b83f5eeeca18ee599ae6f07dbd43”,
“Created”: “2019-03-08T06:05:20.928625042Z”,
“Path”: “/bin/bash”,
“Args”: [],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 11268,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2019-03-08T06:05:21.389114825Z”,
“FinishedAt”: “0001-01-01T00:00:00Z”
………..
在容器中运行命令
docker exec test01 ls
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
在容器中运行命令
docker exec -it test01 ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
docker exec -it test01 /bin/bash
root@a9938874cd94:/#
root@a9938874cd94:/#
查看容器状态:
docker top test01
UID PID PPID C STIME TTY TIME CMD
root 11268 11252 0 01:05 pts/0 00:00:00 /bin/bash
root 11536 11252 0 01:10 ? 00:00:00 /bin/bash
root 11572 11252 0 01:10 ? 00:00:00 /bin/bash
root 11612 11252 0 01:11 ? 00:00:00 /bin/bash
拷贝文件:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16d6eb695656 ubuntu:self1 “/bin/bash” 6 seconds ago Up 5 seconds test02
a9938874cd94 ubuntu:self “/bin/bash” 13 minutes ago Up 12 minutes test01
root@a9938874cd94:/# cd /home/
root@a9938874cd94:/home# touch a.txt
root@a9938874cd94:/home# touch b.txt
docker cp test01:/home/a.txt ~/
[root@localhost ~]
# ll
total 88556
-rw——-. 1 root root 1260 Apr 1 2018 anaconda-ks.cfg
-rw-r–r– 1 root root 0 Mar 8 01:18 a.txt
-rw-r–r– 1 root root 90673664 Mar 7 09:11 test01.tar
查看容器映射的端口
docker port dnat
80/tcp -> 0.0.0.0:88
查看容器日志
docker logs dnat
2019-03-24 16:41:36,533 WARN No file matches via include “/etc/supervisor/conf.d/*.conf”
2019-03-24 16:41:36,533 INFO Set uid to user 0 succeeded
2019-03-24 16:41:36,553 INFO RPC interface ‘supervisor’ initialized
2019-03-24 16:41:36,553 CRIT Server ‘unix_http_server’ running without any HTTP authentication checking
2019-03-24 16:41:36,553 INFO supervisord started with pid 1
2019-03-24 16:41:37,568 INFO spawned: ‘php-fpm’ with pid 14
查看容器状态
docker stats dnat
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
715470c8dbe2 dnat 0.01% 22.29MiB / 976.3MiB 2.28% 25.7kB / 430kB 0B / 8.19kB 7
更新容器参数
docker update –help
Usage: docker update [OPTIONS] CONTAINER [CONTAINER…]
Update configuration of one or more containers
Options:
–blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
–cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
–cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
–cpu-rt-period int Limit the CPU real-time period in microseconds
–cpu-rt-runtime int Limit the CPU real-time runtime in microseconds
-c, –cpu-shares int CPU shares (relative weight)
–cpus decimal Number of CPUs
–cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
–cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
–kernel-memory bytes Kernel memory limit
-m, –memory bytes Memory limit
–memory-reservation bytes Memory soft limit
–memory-swap bytes Swap limit equal to memory plus swap: ‘-1’ to enable unlimited swap
–restart string Restart policy to apply when a container exits
# docker events --help
Usage: docker events [OPTIONS]
Get real time events from the server
Options:
-f, –filter filter Filter output based on conditions provided
–format string Format the output using the given Go template
–since string Show all events created since timestamp
–until string Stream events until this timestamp