images
docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Options:
-a, --all 显示所有
--digests 显示镜像manifest内容的sha256值
-f, --filter filter 过滤
--format string 模板输出
--no-trunc 显示详细信息
-q, --quiet 只显示镜像ID
$ docker images --filter "label=com.example.version"
REPOSITORY TAG IMAGE ID CREATED SIZE
match-me-1 latest eeae25ada2aa About a minute ago 188.3 MB
match-me-2 latest dea752e4e117 About a minute ago 188.3 MB
$ docker images --filter "label=com.example.version=1.0"
REPOSITORY TAG IMAGE ID CREATED SIZE
match-me latest 511136ea3c5a About a minute ago 188.3 MB
$ docker images --filter "before=image1"
REPOSITORY TAG IMAGE ID CREATED SIZE
image2 latest dea752e4e117 9 minutes ago 188.3 MB
image3 latest 511136ea3c5a 25 minutes ago 188.3 MB
$ docker images --filter=reference='busy*:*libc'
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox uclibc e02e811dd08f 5 weeks ago 1.09 MB
busybox glibc 21c16b6787c6 5 weeks ago 4.19 MB
$ docker images --format "{
{.ID}}: {
{.Repository}}"
77af4d6b9913: <none>
b6fa739cedf5: committ
78a85c484f71: <none>
30557a29d5ab: docker
5ed6274db6ce: <none>
746b819f315e: postgres
746b819f315e: postgres
746b819f315e: postgres
746b819f315e: postgres
$ docker images --format "table {
{.ID}}\t{
{.Repository}}\t{
{.Tag}}"
IMAGE ID REPOSITORY TAG
77af4d6b9913 <none> <none>
b6fa739cedf5 committ latest
78a85c484f71 <none> <none>
30557a29d5ab docker latest
5ed6274db6ce <none> <none>
746b819f315e postgres 9
746b819f315e postgres 9.3
746b819f315e postgres 9.3.5
746b819f315e postgres latest
rmi
Usage: docker rmi [OPTIONS] IMAGE [IMAGE...]
Options:
-f, --force 强制删除
--no-prune 这个,举个例子吧
第一步:创建一个Dockerfile
FROM centos:7
RUN yum install -y wget
RUN wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz"
RUN tar -xvf redis.tar.gz
第二步: docker build -t liuwei123:1.0 .
第三步: docker rmi liuwei123:1.0 . 此时 注意 删除的输出结果
第四步: 在 docker build -t liuwei123:1.0 . 此时,就是重复第一步
现在假设我们需要重新build 镜像,重新加上新的东西,而中间的步骤,需要保留,不想删除
FROM centos:7
RUN yum install -y wget
RUN wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz"
RUN tar -xvf redis.tar.gz
RUN yum install -y lrzsz # 新添加的内容
我们就可以使用 docker rmi --no-prune liuwei123:1.0 .
--no-prune:其实就是保留了layers
tag
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
save
docker save -o xxx.tar xxxxx:xxx
load
Usage: docker load [OPTIONS]
Options:
-i, --input string 指定导入的文件
-q, --quiet 精简输出信息
一般使用:docker load < xxx.tar
import
导入快照
Usage: docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
Options:
-c, --change list 可以使用Dockerfile 指令
-m, --message string 提交说明的文字
docker import harbor-db.tar liuwei:123
docker import -c "ENV DEBUG=true" harbor-db.tar liuwei:123
docker import -m "hahahah" harbor-db.tar liuwei:123
history
显示镜像构建的历史
Usage: docker history [OPTIONS] IMAGE
Options:
--format string 格式化答应
-H, --human 人类阅读的方式进行输出
--no-trunc 显示详细信息
-q, --quiet Only show numeric IDs
创建一个dockerfile
FROM centos:7
RUN yum install -y wget
RUN wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz"
RUN tar -xvf redis.tar.gz
RUN yum install -y lrzsz
执行命令:
docker build -t liuliu:1.0 .
执行命令:
docker history centos:7 看到是centos7 构建的相关命令
IMAGE CREATED CREATED BY SIZE COMMENT
8652b9f0cb4c 7 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 7 weeks ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B
<missing> 7 weeks ago /bin/sh -c #(nop) ADD file:b3ebbe8bd304723d4… 204MB
执行命令:
docker history liuliu:1.0 看到的是我们dockerfile 相关的命令
IMAGE CREATED CREATED BY SIZE COMMENT
4f7ca3a8f087 23 hours ago /bin/sh -c yum install -y lrzsz 93.7MB
a847c621cb48 23 hours ago /bin/sh -c tar -xvf redis.tar.gz 8.26MB
7e2dad272112 23 hours ago /bin/sh -c wget -O redis.tar.gz "http://down… 1.96MB
fcd57d53b528 23 hours ago /bin/sh -c yum install -y wget 94.1MB
8652b9f0cb4c 7 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 7 weeks ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B
<missing> 7 weeks ago /bin/sh -c #(nop) ADD file:b3ebbe8bd304723d4… 204MB
inspect
获取镜像的元数据
docker image inspect xxxx:xxx
prune
删除 所有未被 tag 标记和未被容器使用的镜像:
Usage: docker image prune [OPTIONS]
Options:
-a, --all 所有
--filter filter 过滤进行删除
-f, --force 强制删除
build
Name, shorthand | Default | Description |
---|---|---|
--add-host |
添加host:ip 常用 | |
--build-arg |
添加一些环境变量 常用 | |
--cache-from |
可以使用缓存的镜像 基本不用 https://www.linuxea.com/2314.html | |
--cgroup-parent |
容器可选的父安全组 基本不用 | |
--compress |
使用zip 压缩文件上传dockerdaemon,然后构建上下文 基本不用 | |
--cpu-period |
一般和–cpu-quota 一起使用,假设 --cpu-period=100ms 基本不用 | |
--cpu-quota |
–cpu-quota =200ms 表示:在每 100 毫秒的时间里,运行进程的CPU最多为200ms基本不用 | |
--cpu-shares , -c |
设置CPU权重 基本不用 | |
--cpuset-cpus |
固定CPU 基本不用 | |
--cpuset-mems |
只应用于 NUMA 架构的 CPU 生效 对我们普通人没用 | |
--disable-content-trust |
true |
跳过镜像验证 基本不用 |
--file , -f |
指定Dockerfie 常用 | |
--force-rm |
true | 删除中间环节的容器 默认就行 |
--iidfile |
举例:docker build --iidfile a.yaml -t liuweli:1.0 . 将构建的镜像ID写入文件 不常用 | |
--isolation |
默认–isolation=“default”,即Linux命名空间;其他还有process或hyperv不常用 | |
--label |
为生成的镜像设置metadata 常用 | |
--memory , -m |
内存现在不常用 | |
--memory-swap |
内存不够不常用 | |
--network |
构建镜像使用host网路docker build --network host -t liuweli:1.0 . 常用 | |
--no-cache |
不使用缓存构建镜像不常用 | |
--output , -o |
docker build --output type=tar,dest=liuwei.tar -t liuwei:123 . 生成镜像的同时,打上压缩包 不常用 | |
--platform |
如果服务器支持多平台,则设置平台 没用 | |
–progress | auto | 设置进度输出类型(自动、普通、tty) |
--pull |
总是下载最新的镜像不常用 | |
--quiet , -q |
精简输出不常用 | |
--rm |
true |
成功构建后删除中间容器 |
--secret |
要向构建公开的秘密文件(仅当启用BuildKit时):id=mysecret,src=/local/ Secret 不懂 | |
--security-opt |
安全选项不懂 | |
--shm-size |
/dev/shm大小 虚拟磁盘,直接放在内存里不常用 | |
--squash |
精简镜像,压缩镜像层,打包出来的镜像比较小不常用 | |
--ssh |
SSH代理套接字或密钥暴露给构建(仅当BuildKit启用时)(格式:默认不懂 | |
--stream |
流附加到服务器以协商构建上下文不懂 | |
--tag , -t |
打标签常用 | |
--target |
https://blog.csdn.net/dkfajsldfsdfsd/article/details/88781816 不常用 | |
--ulimit |
和linux ulimit命令差不多不常用 |