码迷,mamicode.com
首页 > 其他好文 > 详细

docker基础:本地镜像管理相关命令

时间:2020-07-11 09:16:30      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:rom   containe   after   list   ide   optional   truncate   中间   url   

blog:https://www.cnblogs.com/Rohn/

本地镜像管理

  • docker images: 列出本地镜像;
  • docker rmi:删除本地镜像;
  • docker tag:标记本地镜像;
  • docker build:使用DockerFile创建镜像;
  • docker history:查看指定镜像的创建历史;
  • docker save:将指定镜像保存成tar归档文件;
  • docker load:导入使用docker save命令导出的镜像;
  • docker import:从归档文件中创建镜像;
  • docker commit:从容器修改中创建新的镜像;

列出本地镜像

语法如下:

docker images [OPTIONS] [REPOSITORY[:TAG]]

Options:
  -a, --all             Show all images (default hides intermediate images(默认隐藏中间镜像层))
      --digests         Show digests(显示摘要信息)
  -f, --filter filter   Filter output based on conditions provided(显示满足条件的镜像)
      --format string   Pretty-print images using a Go template
      --help            Print usage
      --no-trunc        Don‘t truncate output(显示完整的镜像信息)
  -q, --quiet           Only show numeric IDs

删除本地镜像

语法如下:

docker rmi [OPTIONS] IMAGE [IMAGE...]

Options:
  -f, --force      Force removal of the image(强制删除镜像)
      --no-prune   Do not delete untagged parents(不移除该镜像的过程镜像,默认移除)

例如:

# 删除所有镜像
docker rmi $(docker images -q) 

# 批量删除无用镜像
docker rmi $(docker images -f dangling=true)

标记本地镜像

语法如下:

docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

使用DockerFile创建镜像

语法如下:

docker build [OPTIONS] PATH | URL | -

Options:
      --build-arg list             Set build-time variables (default [])
      --cache-from stringSlice     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
      --help                       Print usage
      --isolation string           Container isolation technology
      --label list                 Set metadata for an image (default [])
  -m, --memory string              Memory limit
      --memory-swap string         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 stringSlice   Security options
      --shm-size string            Size of /dev/shm, default value is 64MB
  -t, --tag list                   Name and optionally a tag in the ‘name:tag‘ format (default [])
      --ulimit ulimit              Ulimit options (default [])

查看指定镜像的创建历史

语法如下:

docker history [OPTIONS] IMAGE

Options:
  -H, --human      Print sizes and dates in human readable format (default true)
      --no-trunc   Don‘t truncate output
  -q, --quiet      Only show numeric IDs

镜像保存

语法如下:

docker save [OPTIONS] IMAGE [IMAGE...]

Options:
  -o, --output string   Write to a file, instead of STDOUT

镜像导入

语法如下:

docker load [OPTIONS]

Options:
  -i, --input string   Read from tar archive file, instead of STDIN
  -q, --quiet          Suppress the load output

从归档文件中创建镜像

语法如下:

docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

Options:
  -c, --change list      Apply Dockerfile instruction to the created image (default [])
  -m, --message string   Set commit message for imported image

从容器修改中创建新镜像

语法如下:

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Options:
  -a, --author string    Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  -c, --change list      Apply Dockerfile instruction to the created image (default [])
  -m, --message string   Commit message
  -p, --pause            Pause container during commit (default true)

docker基础:本地镜像管理相关命令

标签:rom   containe   after   list   ide   optional   truncate   中间   url   

原文地址:https://www.cnblogs.com/Rohn/p/13282373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!