Skip to content

Docker image tagging and pushing

Docker image tagging and pushing are the processes used to prepare an image for distribution and upload it to a Docker Registry (such as Docker Hub or a private repository).^[600-developer-docker-docker.md]

Workflow

The general workflow for sharing a Docker image involves three sequential steps: logging in to the registry, tagging the image with the appropriate target notation, and pushing the image.^[600-developer-docker-docker.md]

  1. Log in: Authenticate with the registry using docker login.^[600-developer-docker-docker.md]
  2. Tag: Apply a tag to the local image that corresponds to the destination username/repository.^[600-developer-docker-docker.md]
  3. Push: Upload the tagged image to the registry using docker push username/repository:tag.^[600-developer-docker-docker.md]

Tagging Images

The docker tag command is used to create a new alias for an existing image ID, effectively targeting it for a specific registry.^[600-developer-docker-docker.md] The syntax requires the source image and the target notation.

For example, to tag a local image for Docker Hub:

docker tag docker.io/hello-world yudady/hello
^[600-developer-docker-docker.md]

After tagging, running docker images will display the new repository name pointing to the same underlying image ID.^[600-developer-docker-docker.md]

Pushing Images

Once tagged, the docker push command uploads the image layers to the specified repository.^[600-developer-docker-docker.md]

Example command:

docker push yudady/hello
^[600-developer-docker-docker.md]

The Docker daemon will output the digest (e.g., sha256:...) and the size of the uploaded layers to confirm a successful push.^[600-developer-docker-docker.md]

Private Registries

When working with a private registry (e.g., hosted on localhost:5000), the tagging process must include the registry server address and port.^[600-developer-docker-dockerfile-dockerfile-01.md]

  1. Tag for private registry:
    docker tag mytomcat 127.0.0.1:5000/mytomcat
    
    ^[600-developer-docker-dockerfile-dockerfile-01.md]
  2. Push to private registry:
    docker push 127.0.0.1:5000/mytomcat
    
    ^[600-developer-docker-dockerfile-dockerfile-01.md]

To verify the image is stored in the private registry, you can query the catalog via the API:

curl -X GET http://127.0.0.1:5000/v2/_catalog
^[600-developer-docker-dockerfile-dockerfile-01.md]

Sources

  • 600-developer-docker-docker.md
  • 600-developer-docker-dockerfile-dockerfile-01.md