麦克斯仇
Think different
159
文章
27969
阅读
首页
INDEX
文章
ARTICLE
关于
ABOUT
Docker命令1:docker image(管理镜像)
创建日期:
2020/01/09
修改日期:
2022/06/22
Docker
### pull 拉取镜像 ```bash docker pull [OPTIONS] NAME[:TAG|@DIGEST] docker image pull [OPTIONS] NAME[:TAG|@DIGEST] Options: -a, --all-tags Download all tagged images in the repository # 下载所有的标签 --disable-content-trust Skip image verification (default true) # 跳过镜像验证 -q, --quiet Suppress verbose output # 静默下载 ``` ```bash # 拉取一个镜像 docker pull centos # 拉取指定版本的镜像 docker pull centos:7 ``` ### ls 列出镜像 ```bash docker images [OPTIONS] [REPOSITORY[:TAG]] docker image ls [OPTIONS] [REPOSITORY[:TAG]] Options: -a, --all Show all images (default hides intermediate images) # 展示所有镜像(默认隐藏中间镜像) --digests Show digests # 显示DIGEST -f, --filter filter Filter output based on conditions provided --format string Pretty-print images using a Go template --no-trunc Don't truncate output # 显示完整IMAGE ID -q, --quiet Only show numeric IDs # 仅显示IMAGE ID ``` ``` # 列出所有的镜像 docker images # 列出所有的镜像(包含docker build产生的中间镜像) docker images -a ``` 列 | 说明 | 注 ---|---|--- REPOSITORY | 名称 | TAG | 标签 | DIGEST | 摘要 | 加 --digests 显示 IMAGE ID | ID | CREATED | 创建时间 | SIZE | 大小 | ### inspect 显示一个或多个镜像的详细信息 ```bash docker image inspect [OPTIONS] IMAGE [IMAGE...] # 此命令可以简写如下命令,但是 docker inspect 不仅仅可以查看 IMAGE docker inspect [OPTIONS] NAME|ID [NAME|ID...] Options: -f, --format string Format the output using the given Go template ``` ```bash # 显示一个镜像的详细信息 docker image inspect mysql:latest ``` > inspect详细内容后期整理 ### rm 删除一个或多个镜像 ```bash docker rmi [OPTIONS] IMAGE [IMAGE...] docker image rm [OPTIONS] IMAGE [IMAGE...] Options: -f, --force Force removal of the image # 强制 --no-prune Do not delete untagged parents # 不删除未标记的父。。。 ``` ```bash # 删除指定镜像 docker rmi centos:7 ``` 命令中 IMAGE 可以写 REPOSITORY 或 IMAGE ID REPOSITORY 不可简写,可以写几个字母后使用tab键自动补全, IMAGE ID 可以简写,简写至可以唯一确定即可,简写规则同容器操作简写规则 ### prune 删除未使用的镜像 ```bash docker image prune [OPTIONS] Options: -a, --all Remove all unused images, not just dangling ones # 删除所有未使用的,而非dangling --filter filter Provide filter values (e.g. 'until=<timestamp>') # 过滤器 -f, --force Do not prompt for confirmation # 不提示确认 ``` ```bash # 清理所有未使用的镜像(-f 不提示确认) docker image prune -af ``` ### build 从一个Dockerfile制作一个镜像 ```bash docker build [OPTIONS] PATH | URL | - docker image build [OPTIONS] PATH | URL | - docker builder build [OPTIONS] PATH | URL | - Options: --add-host list Add a custom host-to-IP mapping (host:ip) --build-arg list Set build-time variables --cache-from strings Images to consider as cache sources --cgroup-parent string Optional parent cgroup for the container --compress Compress the build context using gzip --cpu-period int Limit the CPU CFS (Completely Fair Scheduler) period --cpu-quota int Limit the CPU CFS (Completely Fair Scheduler) quota -c, --cpu-shares int CPU shares (relative weight) --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) --disable-content-trust Skip image verification (default true) -f, --file string Name of the Dockerfile (Default is 'PATH/Dockerfile') --force-rm Always remove intermediate containers --iidfile string Write the image ID to the file --isolation string Container isolation technology --label list Set metadata for an image -m, --memory bytes Memory limit --memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap --network string Set the networking mode for the RUN instructions during build (default "default") --no-cache Do not use cache when building the image --pull Always attempt to pull a newer version of the image -q, --quiet Suppress the build output and print image ID on success --rm Remove intermediate containers after a successful build (default true) --security-opt strings Security options --shm-size bytes Size of /dev/shm -t, --tag list Name and optionally a tag in the 'name:tag' format # 命名名称 --target string Set the target build stage to build. --ulimit ulimit Ulimit options (default []) ``` ```bash # 从当前路径build一个镜像,标签为demo docker build -t demo . # 从当前路径build一个镜像,标签为demo,版本为V1 docker build -t demo:V1 . ``` ### history 显示镜像制作过程 ```bash docker history [OPTIONS] IMAGE docker image history [OPTIONS] IMAGE Options: --format string Pretty-print images using a Go template -H, --human Print sizes and dates in human readable format (default true) #显示完整时间以及大小 --no-trunc Don't truncate output # 显示完整脚本 -q, --quiet Only show numeric IDs # 仅显示ID ``` ```bash # 显示指定镜像的制作步骤 docker history centos:latest ``` 列 | 说明 | 注 ---|---|--- IMAGE | 生成的镜像ID | CREATED | 创建时间 | 具体时间加 -H CREATED BY | 执行的命令 | 完整命令加 -no-trunc SIZE | 产生的文件大小 | COMMENT | 备注 | ### tar 创建一个引用SOURCE_IMAGE的TARGET_IMAGE标记 ```bash docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] docker image tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] ``` ```bash # 给镜像重新打标签 docker tag web:latest web:1.0 ``` ### push 推送一个镜像值容器镜像服务 ```bash docker push [OPTIONS] NAME[:TAG] docker image push [OPTIONS] NAME[:TAG] Options: --disable-content-trust Skip image signing (default true) ``` ```bash # 推送一个镜像 docker push qzhing/centos_with_vim ``` ### save 将一个或多个镜像保存到tar存档(默认情况下流到STDOUT) ```bash docker save [OPTIONS] IMAGE [IMAGE...] docker image save [OPTIONS] IMAGE [IMAGE...] Options: -o, --output string Write to a file, instead of STDOUT # 写入文件,而不是STDOUT ``` ```bash # 将 MySQL 镜像存储为 mysql.tar 文件 docker save -o mysql.tar mysql:5.7.28 ``` ### load 从tar存档或STDIN加载镜像 ```bash docker load [OPTIONS] docker image load [OPTIONS] Options: -i, --input string Read from tar archive file, instead of STDIN # 从tar归档文件而不是STDIN中读取 -q, --quiet Suppress the load output ``` ```bash # 导入一个镜像文件 docker load -i mysql.tar ``` ### import 从tarball导入内容以创建文件系统映像 ```bash docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]] docker image import [OPTIONS] file|URL|- [REPOSITORY[:TAG]] Options: -c, --change list Apply Dockerfile instruction to the created image -m, --message string Set commit message for imported image ``` > 未完善,待更新
41
全部评论