Home > Enterprise >  How to pull a docker image after tag
How to pull a docker image after tag

Time:05-12

Is it possible to docker pull from a private repository if you tag a new name and delete the original one?

For example,

docker pull harbor.mycompany.com/something/batman:1.0            # pull from remote repo
docker tag harbor.mycompany.com/something/batman:1.0 batman:1.0  # rename to pretty name
docker rmi harbor.mycompany.com/something/batman:1.0             # delete ugly name
docker pull batman:1.0                                           # does not work

This related post shows how to change the docker image name but does not address pulling from Harbor or a private repo: Docker how to change repository name or rename image?

CodePudding user response:

docker pull always needs a registry-qualified name. If you don't provide one, it defaults to docker.io/library/... as a prefix. Tagging a local image with another name doesn't keep any memory of where the original image might have come from.

I'd recommend always using the registry-qualified name with its original tag. If you can't encapsulate this in something like a Docker Compose setup, you can at least use shell variables to simplify this

REGISTRY=harbor.example.com
IMAGE=something/batman
TAG=1.0
FULL_IMAGE="$REGISTRY/$IMAGE:$TAG"

docker build -t "$FULL_IMAGE" .
docker run -d --name container_name -p 8000:8000 "$FULL_IMAGE"
./integration_tests http://localhost:8000
docker stop container_name
docker rm container_name
docker push "$FULL_IMAGE"
docker rmi "$FULL_IMAGE"

docker pull "$FULL_IMAGE"
  • Related