17

I have a private docker repo in which i have 10 container images stored. I want to pull all images to a machine. is there a way i can pull all images from a repo with a single command? some command like

docker pull  xx.xx.com/reponame/* 

while researching I found ways to pull all tags of a single image; but no luck so far on all images

8 Answers 8

17

Try this (it will update images that does not have running containers directly attached to them)

docker images | awk '(NR>1) && ($2!~/none/) {print $1":"$2}' | xargs -L1 docker pull

Try out this line out first to see what images will be covered:

docker images | awk '(NR>1) && ($2!~/none/) {print $1":"$2}'
1
  • maybe add a prune at the end: docker image ls | awk '(NR>1) && ($2!~/none/) {print $1":"$2}' | xargs -L1 docker image pull; docker image prune -f
    – Mystic
    Commented Mar 10, 2023 at 6:07
10

Could 'hack' this with docker-compose.

# docker-compose.yml
version: '3.1'
services:
  a:
    image: a-image
  b:
    image: b-image
  c:
    image: c-image
# .....

docker-compose pull --parallel

2
  • Thank you for this! I was looking to do something different than what the question was. I came across your answer which worked for what I needed. Thanks for this hack. Commented Mar 6, 2022 at 5:17
  • This was exactly what I was after, thanks Commented Jan 15 at 19:31
6

Use the format tag to filter the repository list. Although this will only pull the ones already existing in your host.

for image in $(docker images --format "{{.Repository}}"); do docker pull $image; done
5

Regarding the docker documentation of the command: docker pull, you could use the option

--all-tags

to download all tagged images in the repository.

In your case, it would be :

docker pull --all-tags  xx.xx.com/reponame 
1
  • This command is not working in my case? is it working for you? Commented Apr 4, 2022 at 13:14
2

Not sure what type of command is a single command, one-liner?

for repo in repo1 repo2 repo3; do docker pull xx.xx.com/$repo; done
2

Run below shell script to pull ALL DOCKER IMAGES with ALL TAGS from a Docker Registry at once,

SHELL SCRIPT:

#/bin/bash
set-x
registry="registry name/ip:port"
repos=`curl -u cloudfx:cFx2018Aug http://$registry/v2/_catalog?n=300 | jq '.repositories[]' | tr -d '"'`
for repo in $repos; do 
   docker pull --all-tags $registry/$repo;
done
1

Easy.

Install jq to parse JSON, edit the REGISTRY variable and run this script:

#!/bin/sh

REGISTRY="http://registry:5000"

for repo in $(curl -s $REGISTRY/v2/_catalog | jq -r '.repositories[]') ; do
    for tag in $(curl -s $REGISTRY/v2/$repo/tags/list | jq -r '.tags[]') ; do
        docker pull $REGISTRY/$repo:$tag
    done
done

For details on the Docker Registry API: https://github.com/docker/distribution/blob/master/docs/spec/api.md

1
  • This will use a lot of bandwidth and space to fetch all of those images. It's a shame there seems to be no way to add a repository that's searched on demand when an image is requested. You might get away with putting a full repo path in the Dockerfile rather than pre-fetching all of them to have as dependencies but I've not tested this.
    – jgmjgm
    Commented Nov 10, 2017 at 16:28
0

I had a similar requirement - I needed to pull a specific set of tags from our ACR and found serially pulling using "docker pull" to be network inefficient. So I took @johnharris85 answer and wrote a script taking my version tag

#!/bin/bash

export VERSION_TAG=${1:-latest}

cat <<EOF | docker compose -f - pull 
version: '3.7'
services:
  a:
    image: a-image:${VERSION_TAG}
  b:
    image: b-image:${VERSION_TAG}
  c:
    image: c-image:${VERSION_TAG}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.