查看状态
$ service docker status
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-05-29 06:28:36 UTC; 23h ago
Docs: https://docs.docker.com
Main PID: 22425 (dockerd)
Tasks: 13
CGroup: /system.slice/docker.service
└─22425 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
May 29 06:28:36 ip-172-31-0-144 dockerd[22425]: time="2020-05-29T06:28:36.096004914Z" level=warning msg="Your kernel does
May 29 06:28:36 ip-172-31-0-144 dockerd[22425]: time="2020-05-29T06:28:36.096054961Z" level=warning msg="Your kernel does
May 29 06:28:36 ip-172-31-0-144 dockerd[22425]: time="2020-05-29T06:28:36.096068292Z" level=warning msg="Your kernel does
May 29 06:28:36 ip-172-31-0-144 dockerd[22425]: time="2020-05-29T06:28:36.096297293Z" level=info msg="Loading containers:
May 29 06:28:36 ip-172-31-0-144 dockerd[22425]: time="2020-05-29T06:28:36.255549718Z" level=info msg="Default bridge (doc
May 29 06:28:36 ip-172-31-0-144 dockerd[22425]: time="2020-05-29T06:28:36.394778299Z" level=info msg="Loading containers:
May 29 06:28:36 ip-172-31-0-144 dockerd[22425]: time="2020-05-29T06:28:36.449962198Z" level=info msg="Docker daemon" comm
May 29 06:28:36 ip-172-31-0-144 dockerd[22425]: time="2020-05-29T06:28:36.450103533Z" level=info msg="Daemon has complete
May 29 06:28:36 ip-172-31-0-144 dockerd[22425]: time="2020-05-29T06:28:36.477322125Z" level=info msg="API listen on /var/
May 29 06:28:36 ip-172-31-0-144 systemd[1]: Started Docker Application Container Engine.
lines 1-19/19 (END)
查看概要
$ docker info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 1
Server Version: 19.03.10
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.15.0-1043-aws
Operating System: Ubuntu 18.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.806GiB
Name: ip-172-31-0-144
ID: KJXS:PACL:2HXV:OC5G:ASO7:QK5T:HHZ7:WJXA:VPD7:WCFN:CDRZ:HPLJ
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No swap limit support
镜像列表
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx/unit latest c3609c1acd08 11 days ago 236MB
hello-world latest fce289e99eb9 12 months ago 1.84kB
创建容器
// 使用host网络模式 https://docs.docker.com/network/host/
// The -d flag means to start the container detached (in the background).
$ docker run -d --network host --mount type=bind,source="$(pwd)",target=/_projects nginx/unit
5d579574130076b6dc72832b5ffeff6c47a3909a0573e734bca33e6249cc67a9
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5d5795741300 nginx/unit "/usr/local/bin/dock…" 40 seconds ago Up 39 seconds keen_goldwasser
创建容器时完成文件路径和网络端口映射:
1. 将本地路径 /Users/worldzhy/src 映射到容器中 /home/worldzhy/src 这个位置;
2. 将容器中将本地的 3001 端口映射到容器中的 3000 端口;
3. node 为镜像的名字。
$ docker run -it -v /Users/worldzhy/src:/home/worldzhy/src -p 3001:3000 node
停止容器
$ docker stop a9a27b0b8ebf
a9a27b0b8ebf
重启容器
$ docker restart 26ee27816e24
26ee27816e24
容器列表
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
907eaccbb75c nginx/unit "/usr/local/bin/dock…" 2 minutes ago Exited (0) 8 seconds ago quizzical_williamson
42f8d0c94ba4 nginx/unit "/usr/local/bin/dock…" 3 minutes ago Exited (0) 2 minutes ago peaceful_hamilton
删除容器
$ docker rm 907eaccbb75c
907eaccbb75c
// 删除所有停止的容器
$ docker rm $(docker ps -aq)
进入容器 退出容器
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26ee27816e24 c3609c1acd08 "/usr/local/bin/dock…" 10 minutes ago Up 8 minutes heuristic_faraday
$ sudo docker exec -it 26ee27816e24 /bin/bash
root@26ee27816e24:/#
root@26ee27816e24:/# exit
exit
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26ee27816e24 c3609c1acd08 "/usr/local/bin/dock…" 12 minutes ago Up 10 minutes heuristic_faraday
查看容器详情(数据很多)
$ docker inspect 26ee27816e24
创建镜像
$ docker commit [container ID / container name]
创建镜像标签
// worldzhy 是 DockerHub 账号,node 是镜像名字,v1.1 是镜像标签。
$ docker tag [image ID] worldzhy/node:v1.1