«

docker镜像批量下载的小技巧

Linux-man.cn 发布于 阅读:44 技术文章


docker pull命令不支持接多个镜像地址或者从文本读取镜像地址。

docker pull -h
Flag shorthand -h has been deprecated, please use --help

Usage:  docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Download an image from a registry

Aliases:
  docker image pull, docker pull

Options:
  -a, --all-tags                Download all tagged images in the repository
      --disable-content-trust   Skip image verification (default true)
      --platform string         Set platform if server is multi-platform capable
  -q, --quiet                   Suppress verbose output

那么下载多个镜像通常会写个for循环(挨个下载),有没有其它更酷的方式,答案当然是有,借助docker compose:

docker compose pull -h
Flag shorthand -h has been deprecated, please use --help

Usage:  docker compose pull [OPTIONS] [SERVICE...]

Pull service images

Options:
      --dry-run                Execute command in dry run mode
      --ignore-buildable       Ignore images that can be built.
      --ignore-pull-failures   Pull what it can and ignores images with pull failures.
      --include-deps           Also pull services declared as dependencies.
  -q, --quiet                  Pull without printing progress information.

例如,可以这样写个docker compose文件:

version: '3.3'
services:  
    nginx1:    
        image: myscale/myscaledb:1.6.4  
    nginx2:    
        image: opensearchproject/opensearch-dashboards:latest  
    nginx3:    
        image: langgenius/dify-api:0.15.3  
    nginx4:    
        image: langgenius/dify-web:0.15.3  
    nginx5:    
        image: postgres:15-alpine  
    nginx6:    
        image: redis:6-alpine

然后执行

docker compose -f docker-compose-test.yaml pull


接下来就会如上图所示,刷刷刷的在下载镜像了。

备注:新版本会同时pull多个镜像,旧版本需要加个参数,help看下吧。

好了,就这样。

docker linux