Loading...

How to use docker push

Jonas Scholz
3 min read 15. Okt. 2024

When you've created a Docker image and want to share it with others or use it across different environments, you'll need to push it to a Docker registry. Let's walk through how to do that using the docker push command.

First off, the docker push command is essentially a shorthand for docker image push. It's used to upload your Docker image to a registry, which could be Docker Hub or a self-hosted registry. Here's how it works:

Basic Usage

To push an image, you'll use a command that looks like this:

docker push NAME[:TAG]

For instance, if you have an image named myimage with a tag latest, you'd push it like this:

docker push myimage:latest

If you don't specify a tag, Docker will try to push the image with the latest tag by default.

Tagging Before Pushing

Before you can push an image, you need to tag it with the registry's address. Let's say you want to push an image to Docker Hub and your username there is myusername. You would tag your image like this:

docker tag myimage:latest myusername/myimage:latest

Then, you can push it:

docker push myusername/myimage:latest

If you're pushing to a private registry, say on a server named registry-host on port 5000, you'd tag and push like this:

docker tag myimage:latest registry-host:5000/myimage:latest
docker push registry-host:5000/myimage:latest

Managing Credentials

To push to a registry that requires authentication, like Docker Hub, you'll need to log in first using:

docker login

This command will prompt you for your username and password. Once logged in, Docker will use these credentials for your push operations.

Pushing All Tags

If you want to push all tags of an image at once, you can use the --all-tags or -a option. Let's say you have an image myimage with multiple tags (v1, v2, latest). You can push all these tags with:

docker push --all-tags myusername/myimage

Disabling Content Trust

By default, Docker uses content trust to sign images. If you want to skip this and push unsigned images, you can use:

docker push --disable-content-trust myusername/myimage:latest

Pushing Platform-Specific Images

If you're working with images that are specific to certain platforms, you can specify this during the push. For example, to push an image for Linux on AMD64 architecture:

docker push --platform linux/amd64 myusername/myimage:latest

Quiet Mode

If you don't want to see the progress bars and other verbose output during the push, you can use the quiet mode:

docker push -q myusername/myimage:latest

What to Expect

When you start a push, Docker will show you progress bars indicating the size of the data being uploaded. Remember, these bars show the uncompressed size, and the actual data sent will be smaller because it's compressed.

If you need to stop the push, you can press CTRL-c. This will terminate the process, but you'll need to restart the push from the beginning if you want to complete it.

Concurrent Uploads

Docker pushes images in layers, and by default, it tries to upload five layers at once. If you're on a slow connection, this might cause issues. You can adjust this setting in the Docker daemon configuration with the --max-concurrent-uploads option.

Verifying the Push

After pushing an image, you can check if it's available in the registry. For Docker Hub, you can visit the website. For a private registry, you might need to use a command like docker images to see if the image is listed with the registry's address.

That's it! By following these steps, you should be able to push your Docker images to any registry you need.

Welcome to the container cloud

Sliplane makes it simple to deploy containers in the cloud and scale up as you grow. Try it now and get started in minutes!