Docker 深入

什么是 Docker ?

Enterprise Container Platform for High-Velocity Innovation
高速创新的企业集装箱平台

Securely build, share and run any application, anywhere
在任何地方安全地构建,共享和运行任何应用程序

什么是容器 ?

容器是一个标准的软件单元,它将代码及其所有依赖关系打包,以便应用程序从一个计算环境快速可靠地运行到另一个计算环境。

Docker安装在原来的博客有讲到,这里就讲Docker的使用及实例

Docker使用

Docker Hello World

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@caoxl ~]# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

Docker 容器使用

Docker 客户端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
[root@caoxl ~]# docker

Usage: docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
--config string Location of client config files (default "/root/.docker")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default
"info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit

Management Commands:
builder Manage builds
config Manage Docker configs
container Manage containers
engine Manage the docker engine
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes

Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

可以通过命令 docker command --help 更深入的了解指定的 Docker 命令使用方法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@caoxl ~]# docker ps --help

Usage: docker ps [OPTIONS]

List containers

Options:
-a, --all Show all containers (default shows just running)
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print containers using a Go template
-n, --last int Show n last created containers (includes all states) (default -1)
-l, --latest Show the latest created container (includes all states)
--no-trunc Don't truncate output
-q, --quiet Only display numeric IDs
-s, --size Display total file sizes

运行一个Web应用

接下来让我们尝试使用 docker 构建一个 web 应用程序。

我们将在docker容器中运行一个 Python Flask 应用来运行一个web应用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@caoxl ~]# docker pull training/webapp
Using default tag: latest
latest: Pulling from training/webapp
e190868d63f8: Pull complete
909cd34c6fd7: Pull complete
0b9bfabab7c1: Pull complete
a3ed95caeb02: Pull complete
10bbbc0fc0ff: Pull complete
fca59b508e9f: Pull complete
e7ae2541b15b: Pull complete
9dd97ef58ce9: Pull complete
a4c1b0cb7af7: Pull complete
Digest: sha256:06e9c1983bd6d5db5fba376ccd63bfa529e8d02f23d5079b8f74a616308fb11d
Status: Downloaded newer image for training/webapp:latest

[root@caoxl ~]# docker run -d -P training/webapp python app.py
fc14b64cda1d2445bcea207ece36b9b274f3a422be26c92bd95cbe1af96d0d6e
  • 参数说明
    • -d: 让容器在后台运行
    • -P: 将容器内部使用的网络端口映射到我们使用的手机上

查看WEB应用容器

1
2
3
4
[root@caoxl ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fc14b64cda1d training/webapp "python app.py" About a minute ago Up About a minute 0.0.0.0:32768->5000/tcp hopeful_mendel
c4d4afebb0d1 pinguo/php-msf-demo:newdev "/run.sh /usr/sbin/s…" 27 minutes ago Up 27 minutes 0.0.0.0:443->443/tcp, 80/tcp, 0.0.0.0:8000->8000/tcp, 0.0.0.0:2202->22/tcp pinguo_php-msf-demo_newdev

停止Web应用容器,使用NAMES

1
2
[root@caoxl ~]# docker stop hopeful_mendel
hopeful_mendel

重启WEB应用容器

1
2
[root@caoxl ~]# docker start hopeful_mendel
hopeful_mendel

移除WEB应用容器

1
2
[root@caoxl ~]# docker rm hopeful_mendel
hopeful_mendel

删除容器时,容器必须是停止状态,否则会报错误

Docker 镜像使用

列出镜像列表

1
2
3
4
5
6
[root@caoxl ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest fce289e99eb9 4 months ago 1.84kB
pinguo/php-msf-demo newdev 39995bac5087 18 months ago 1.54GB
registry.cn-hangzhou.aliyuncs.com/pinguo-ops/php-msf-docker latest 39995bac5087 18 months ago 1.54GB
training/webapp latest 6fae60ef3446 4 years ago 349MB
  • 各个选项说明
    • REPOSITORY: 表示镜像的仓库源
    • TAG: 镜像的标签
    • IMAGE ID: 镜像ID
    • CREATED: 镜像创建时间
    • SIZE: 镜像大小

查找镜像

1
2
3
4
5
6
7
8
9
10
11
12
[root@caoxl ~]# docker pull skiychan/nginx-php7
Using default tag: latest
latest: Pulling from skiychan/nginx-php7
8ba884070f61: Pull complete
3c273468b2f5: Pull complete
d2c95013bbb4: Pull complete
4c3d9a8120f6: Pull complete
f84b131a51d1: Pull complete
509155c099f5: Pull complete
c24ed08ea428: Pull complete
Digest: sha256:040a3047d85daa7b0f083479dffbc54a034e60e8da0edcc9570047da402c411b
Status: Downloaded newer image for skiychan/nginx-php7:latest

获取一个新的镜像

1
2
[root@caoxl ~]# docker pull skiychan/nginx-php7
Using default tag: latest

Docker 容器连接

Docker实例

Docker 安装Nginx

1
2
3
4
5
6
[root@caoxl ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 11403 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1600 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 712 [OK]
...
  • 拉取官方的镜像
1
2
3
4
5
6
7
8
[root@caoxl ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
743f2d6c1f65: Pull complete
6bfc4ec4420a: Pull complete
688a776db95f: Pull complete
Digest: sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Status: Downloaded newer image for nginx:latest
  • 以下命令使用 NGINX 默认的配置来启动一个 Nginx 容器实例:
1
2
[root@caoxl ~]# docker run --name caoxl -p 8081:80 -d nginx
1e13c99fa213152f2b5220a32254e658f72fd7fc8ce8e6d0a056fe87f74993a2

执行以上命令会生成一串字符串,类似 6dd4380ba70820bd2acc55ed2b326dd8c0ac7c93f68f0067daecad82aef5f938,这个表示容器的 ID,一般可作为日志的文件名。

  • --name 容器名称
  • -d 设置容器在后台一直运行
  • -p 端口进行映射,将本地8081端口映射到容器内部的80端口
1
2
3
[root@caoxl ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e13c99fa213 nginx "nginx -g 'daemon of…" 17 seconds ago Up 16 seconds 0.0.0.0:8081->80/tcp caoxl

相关命令

  • 如果要重新载入 NGINX 可以使用以下命令发送 HUP 信号到容器:
1
docker kill -s HUP nginx # container-name 容器名称,即docker ps 中的NAMES列
  • 重启 Nginx 容器命令
1
docker restart nginx
  • 移除容器
1
2
3
4
5
6
7
8
9
10
11
12
# 移除容器前,需要停止容器
[root@caoxl ~]# docker stop 1e13c99fa213
1e13c99fa213
[root@caoxl ~]# docker rm 1e13c99fa213
1e13c99fa213

# ps 列出运行的容器列表
[root@caoxl ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# ps -a 列出所有容器列表
[root@caoxl ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

Docker 安装PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 先查找php镜像
[root@caoxl ~]# docker search php

# 这里我们拉取官方的镜像,标签为7.2-fpm
[root@caoxl ~]# docker pull php:7.2-fpm
7.2-fpm: Pulling from library/php
743f2d6c1f65: Already exists
6307e89982cc: Already exists
807218e72ce2: Already exists
5108df1d03f8: Already exists
82ffe3f78be2: Pull complete
17c66bee581c: Pull complete
03011f3bcf78: Pull complete
28b6a4179c3e: Pull complete
b77fa38a9e9c: Pull complete
79928611774d: Pull complete
Digest: sha256:c50c0cffd2af10291d8b8fe3dd410aed3eca302b8163e2ab34cd1bfc6feae495
Status: Downloaded newer image for php:7.2-fpm

Docker 安装MySQL

1
2
3
4
[root@caoxl ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 8142 [OK]
mariadb MariaDB is a community-developed fork of MyS… 2771 [OK]

这里我们拉取官方的镜像,标签为5.7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@caoxl ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
743f2d6c1f65: Already exists
3f0c413ee255: Pull complete
aef1ef8f1aac: Pull complete
f9ee573e34cb: Pull complete
3f237e01f153: Pull complete
f9da32e8682a: Pull complete
4b8da52fb357: Pull complete
6f38e9cfd49b: Pull complete
9f4834b3f44f: Pull complete
af631d92fdba: Pull complete
0e771ddab25c: Pull complete
Digest: sha256:196fe3e00d68b2417a8cf13482bdab1fcc2b32cf7c7575d0906c700688b352b4
Status: Downloaded newer image for mysql:5.7

等待下载完成后,我们就可以在本地镜像列表里查到REPOSITORY为mysql,标签为5.6的镜像

1
2
[root@caoxl ~]# docker images | grep mysql
mysql 5.7 7faa3c53e6d6 7 days ago 373MB

Docker 安装Redis

1
2
3
4
[root@caoxl ~]# docker search redis
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
redis Redis is an open source key-value store that… 6900 [OK]
bitnami/redis Bitnami Redis Docker Image 112 [OK]

这里我们拉取官方的镜像,标签为5.0

1
2
3
4
5
6
7
8
9
10
[root@caoxl ~]# docker pull redis:5.0
5.0: Pulling from library/redis
743f2d6c1f65: Already exists
171658c5966d: Pull complete
fbef10bd7a65: Pull complete
98afd60e45e4: Pull complete
495c87fda859: Pull complete
ed6767858416: Pull complete
Digest: sha256:2dfa6432744659268d001d16c39f7be52ee73ef7e1001ff80643f0f7bdee117e
Status: Downloaded newer image for redis:5.0

Docker 命令大全

容器生命周期管理

  • run - 创建一个新的容器并运行一个命令
1
2
[root@caoxl ~]# docker run --name nginx -d nginx:latest
2b077bf72f07ffa1e4e821f02bced02f9265900cc8c0b4dd663a3f90ebb2e8dc
  • start/stop/restart - 启动/停止/重启一个或多个容器
1
2
3
4
5
6
7
8
9
10
11
# 启动一个或多个容器
[root@caoxl ~]# docker start caoxl-php
caoxl-php

# 停止一个运行中的容器
[root@caoxl ~]# docker stop nginx
nginx

# 重启一个已经停止的容器
[root@caoxl ~]# docker restart nginx
nginx
  • kill - 杀掉一个运行中的容器
1
2
3
# 杀掉一个运行中的容器
[root@caoxl ~]# docker kill -s KILL nginx
nginx
  • rm - 删除一个或多个容器(需先停止容器)
1
2
3
4
5
6
7
# 删除一个或多个容器(需先停止容器)
[root@caoxl ~]# docker rm ade302349866
Error response from daemon: You cannot remove a running container ade30234986633c113e9b1e5828d6e6e1f8f74c47cdb878674cec1a2e4a7db3d. Stop the container before attempting removal or force remove

# 强制删除
[root@caoxl ~]# docker rm -f ade302349866
ade302349866

参数说明:

  • -f: 通过SIGKILL信号强制删除一个运行中的容器
  • -l: 移除容器间的网络连接,而非容器本身
  • -v: 删除与容器关联的卷
  • pasue/unpause - 暂停/恢复容器中的进程
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@caoxl ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9bf46c51c287 nginx "nginx -g 'daemon of…" 34 minutes ago Up 34 minutes 0.0.0.0:8081->80/tcp caoxl-nginx

# 暂停容器中的进程
[root@caoxl ~]# docker pause caoxl-nginx
caoxl-nginx

[root@caoxl ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9bf46c51c287 nginx "nginx -g 'daemon of…" 36 minutes ago Up 36 minutes (Paused) 0.0.0.0:8081->80/tcp caoxl-nginx

# 恢复容器中的进程
[root@caoxl ~]# docker unpause caoxl-nginx
caoxl-nginx
  • create - 创建一个新的容器但不启动
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@caoxl ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 5.0 a4fe14ff1981 7 days ago 95MB
php 7.2-fpm 0be748e55df6 7 days ago 366MB
nginx latest 53f3fd8007f7 7 days ago 109MB
mysql 5.7 7faa3c53e6d6 7 days ago 373MB

# 创建一个新的容器但不启动
[root@caoxl ~]# docker create --name caoxl-mysql mysql:5.7
2af5be371c1586be55e6d80cbd1991c029fa44e2306fe2a22956c876fde5ee38

[root@caoxl ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9bf46c51c287 nginx "nginx -g 'daemon of…" 39 minutes ago Up 39 minutes 0.0.0.0:8081->80/tcp caoxl-nginx

[root@caoxl ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2af5be371c15 mysql:5.7 "docker-entrypoint.s…" 10 seconds ago Created caoxl-mysql
2b077bf72f07 nginx:latest "nginx -g 'daemon of…" 13 minutes ago Exited (137) 7 minutes ago nginx
9bf46c51c287 nginx "nginx -g 'daemon of…" 39 minutes ago Up 39 minutes 0.0.0.0:8081->80/tcp caoxl-nginx
  • exec - 在运行中的容器中执行命令
1
2
3
4
# 在运行中的容器中执行命令
[root@caoxl ~]# docker exec -i -t nginx /bin/bash
root@2b077bf72f07:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

容器操作

  • ps - 列出容器
1
2
3
4
[root@caoxl ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2b077bf72f07 nginx:latest "nginx -g 'daemon of…" 18 minutes ago Up 2 minutes 80/tcp nginx
9bf46c51c287 nginx "nginx -g 'daemon of…" 44 minutes ago Up 43 minutes 0.0.0.0:8081->80/tcp caoxl-nginx

参数说明:

  • -a: 显示所有容器,包括未运行的
  • -f: 根据条件过滤显示的内容
  • -l: 显示最近创建的容器
  • -n: 显示最近创建的n个容器
  • -q: 静默模式,只显示容器编号
  • -s: 显示总的文件大小
  • inspect - 获取容器/镜像的元数据
1
2
3
4
5
6
[root@caoxl ~]# docker inspect nginx
[
{
"Id": "2b077bf72f07ffa1e4e821f02bced02f9265900cc8c0b4dd663a3f90ebb2e8dc",
"Created": "2019-05-15T07:20:48.265101617Z",
...
  • top - 查看容器中运行的进程信息
1
2
3
4
5
6
7
[root@caoxl ~]# docker top nginx
UID PID PPID C STIME TTY TIME CMD
root 27933 27916 0 15:36 ? 00:00:00 nginx: master process nginx -g daemon off;
101 27965 27933 0 15:36 ? 00:00:00 nginx: worker process

# 查看所有运行容器的进程信息
for i in `docker ps |grep Up|awk '{print $1}'`;do echo \ &&docker top $i; done
  • attach - 连接到正在运行的容器
1
[root@caoxl ~]# docker attach --sig-proxy=false nginx
  • logs - 获取容器的日志
1
2
3
4
[root@caoxl ~]# docker logs -f nginx

# 查看容器nginx从2019年5月15后的最新10条日志
[root@caoxl ~]# docker logs --since="2019-05-15" --tail=10 nginx
  • port - 列出指定的容器的端口映射,或者查找将PRIVATE_PORT NAT到面向公众的端口。
1
2
[root@caoxl ~]# docker port caoxl-nginx
80/tcp -> 0.0.0.0:8081

容器rootfs命令

  • commit - 从容器创建一个新的镜像
1
2
3
4
5
6
7
8
# 从容器创建一个新的镜像
[root@caoxl ~]# docker commit -a "caoxl" -m "docker commit" f1069837f3eb redis:commit
sha256:2d77296f02fa8a37890e686a5bc07f4173229044bc53f811b4821244f5db3563

[root@caoxl ~]# docker images | grep redis
redis commit 2d77296f02fa 19 seconds ago 95MB
redis 5.0 a4fe14ff1981 7 days ago 95MB
redis latest a4fe14ff1981 7 days ago 95MB
  • cp - 用于容器和主机直接的数据拷贝
1
2
# 将主机/var/www目录拷贝到容器f1069837f3eb的/www目录下。
[root@caoxl ~]# docker cp /var/www f1069837f3eb:/www/

镜像仓库

  • login/logout - 登陆/退出一个Docker镜像仓库,默认为官方仓库 Docker Hub

前往Docker Hub,注册账号.

1
2
3
4
5
6
7
8
9
10
11
12
# 登陆
[root@caoxl ~]# docker login -u username -p password
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

# 登出
[root@caoxl ~]# docker logout
Removing login credentials for https://index.docker.io/v1/
  • pull - 从镜像仓库中拉取或者更新指定镜像
1
[root@caoxl ~]# docker pull swoft/swoft
  • push - 将本地的镜像上传到镜像仓库,要先登陆到镜像仓库
1
2
[root@caoxl ~]# docker push php:7.2-fpm
The push refers to repository [docker.io/library/php]
  • search - 从Docker Hub查找镜像
1
2
3
4
5
6
root@caoxl ~]# docker search swoole
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
xlight/docker-php7-swoole php7-cli with swoole 28 [OK]
twosee/swoole-coroutine Perfect Swoole Dockerfile for senior develop… 27 [OK]
kong36088/nginx-php7-swoole nginx+php7+swoole拓展,另外自带redis和memcac… 14
...

本地镜像管理

  • images - 列出本地镜像
1
2
3
4
5
6
7
[root@caoxl ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 5.0 a4fe14ff1981 7 days ago 95MB
php 7.2-fpm 0be748e55df6 7 days ago 366MB
nginx latest 53f3fd8007f7 7 days ago 109MB
mysql 5.7 7faa3c53e6d6 7 days ago 373MB
swoft/swoft latest 493b8cc21299 3 months ago 447MB
  • rmi - 删除本地一个或多个镜像
1
2
3
[root@caoxl ~]# docker rmi 2d77296f02fa
Untagged: redis:commit
Deleted: sha256:2d77296f02fa8a37890e686a5bc07f4173229044bc53f811b4821244f5db3563

参数说明:

  • -f: 强制删除
  • --no-prune: 不移除该镜像的过程镜像,默认移除
  • tag - 标记本地镜像,将其归入某一个仓库
1
2
3
4
5
[root@caoxl ~]# docker tag swoft/swoft:latest swoft/swoft:swoft
[root@caoxl ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
swoft/swoft latest 493b8cc21299 3 months ago 447MB
swoft/swoft swoft 493b8cc21299 3 months ago 447MB
  • history - 查看指定镜像的创建历史
1
2
3
4
5
6
7
8
9
10
11
12
13
# 查看本地镜像nginx的创建历史
[root@caoxl ~]# docker history nginx
IMAGE CREATED CREATED BY SIZE COMMENT
53f3fd8007f7 7 days ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B
<missing> 7 days ago /bin/sh -c #(nop) STOPSIGNAL SIGTERM 0B
<missing> 7 days ago /bin/sh -c #(nop) EXPOSE 80 0B
<missing> 7 days ago /bin/sh -c ln -sf /dev/stdout /var/log/nginx… 22B
<missing> 7 days ago /bin/sh -c set -x && apt-get update && apt… 54.1MB
<missing> 7 days ago /bin/sh -c #(nop) ENV NJS_VERSION=1.15.12.0… 0B
<missing> 7 days ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.15.12… 0B
<missing> 7 days ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B
<missing> 7 days ago /bin/sh -c #(nop) CMD ["bash"] 0B
<missing> 7 days ago /bin/sh -c #(nop) ADD file:fcb9328ea4c115670… 55.3MB

info|version

  • info - 显示Docker系统信息,包括镜像和容器数
1
2
3
4
5
6
7
8
# 查看Docker系统信息
[root@caoxl ~]# docker info
Containers: 5
Running: 4
Paused: 0
Stopped: 1
Images: 5
...
  • version - 显示Docker版本信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@caoxl ~]# docker version
Client:
Version: 18.09.6
API version: 1.39
Go version: go1.10.8
Git commit: 481bc77156
Built: Sat May 4 02:34:58 2019
OS/Arch: linux/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 18.09.6
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 481bc77
Built: Sat May 4 02:02:43 2019
OS/Arch: linux/amd64
Experimental: false

常见问题

image is referenced in multiple repositories

  • 查看镜像
1
2
3
4
5
6
7
[root@caoxl ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
php 7.2-fpm 0be748e55df6 7 days ago 366MB
nginx latest 53f3fd8007f7 7 days ago 109MB
mysql 5.7 7faa3c53e6d6 7 days ago 373MB
pinguo/php-msf-demo newdev 39995bac5087 18 months ago 1.54GB
registry.cn-hangzhou.aliyuncs.com/pinguo-ops/php-msf-docker latest 39995bac5087 18 months ago 1.54GB
  • 删除镜像
1
2
[root@caoxl ~]# docker rmi 39995bac5087
Error response from daemon: conflict: unable to delete 39995bac5087 (must be forced) - image is referenced in multiple repositories

仔细观察,发现39995bac5087这个镜像id指向了两个repository,因此无法删除

  • 删除时可以用repository和tag的方式来删除
1
2
3
4
[root@caoxl ~]# docker rmi pinguo/php-msf-demo:newdev
Untagged: pinguo/php-msf-demo:newdev
Deleted: sha256:39995bac5087fa922c2eed5f75ae55fce3b08a0d691cd200d5c1c2879660398f
....
  • 再次查看镜像
1
2
3
4
5
[root@caoxl ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
php 7.2-fpm 0be748e55df6 7 days ago 366MB
nginx latest 53f3fd8007f7 7 days ago 109MB
mysql 5.7 7faa3c53e6d6 7 days ago 373MB

Docker 资源汇总

Docker官方英文资源

Docker国内镜像

参考

Powered by Hexo and Hexo-theme-hiker

Copyright © 2017 - 2021 Keep It Simple And Stupid All Rights Reserved.

访客数 : | 访问量 :