How to push a docker image to a private repository
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Docker images are essential building blocks of Docker containers. Once you've created a Docker image, you may want to store it in a Docker repository for easy access and sharing. While Docker Hub is a popular public repository, you might have use cases where you want to keep your images private. This is where private Docker repositories come in handy. In this guide, we'll walk you through the steps of pushing a Docker image to a private repository.
Prerequisites
Before you start, ensure you have the following installed and configured:
- Docker: Ensure Docker is installed on your machine. You can verify this by running:
- Access to a Private Docker Repository: You should have access credentials for a private Docker repository. This could be a self-hosted Docker Registry, AWS ECR, Google Container Registry, or any other service that supports private Docker repositories.
- Docker Image: Have a Docker image that you want to push to your private repository. If you don't have an image yet, you can create one using a Dockerfile.
Creating a Docker Image
If you haven't already built a Docker image, you can create one using the following Dockerfile example:
Build the Docker image with the following command:
Authenticating with Your Private Repository
You'll need to log in to your private repository to push images. This is typically done using the docker login command. Here's a general syntax:
When prompted, enter your repository username and password or access token.
Example: Logging into AWS ECR
Replace <region> and <aws_account_id> with your respective AWS details.
Tagging the Docker Image
Tag your Docker image so it can be pushed to the correct repository. The tagging format is:
Example
If your private repository URL is registry.example.com/myapprepo and you want to tag your image as v1.0, you would run:
Pushing the Docker Image
After tagging your image, you can push it to your private repository using:
Example
Verification
Once the image is pushed, you can verify it by listing the images in your repository or pulling the image back to your local machine using:
Additional Considerations
- Image Size: Large images may take longer to push. Consider optimizing your Dockerfile to reduce image size.
- Network Latency: Depending on your network speed, pushing images might vary in duration. Ensure a stable and fast connection when pushing large images.
- Security: Always secure your credentials and tokens, especially when using command-line interfaces.
Summary Table
| Step | Description |
| Install Docker | Ensure you have Docker installed and configured. |
| Access Private Registry | Have credentials for accessing a private repository. |
| Build Image | Create a Docker image using a Dockerfile. |
| Login to Registry | Authenticate with your private Docker repository. |
| Tag Image | Tag your Docker image for the target repository. |
| Push Image | Push the tagged image to your private repository. |
| Verify Image | Verify by pulling the image from the repository. |
By following these steps, you can successfully push Docker images to a private repository, ensuring better control over your application's deployment pipeline. Whether for development, testing, or production, securely managing your images in a private repository is a best practice for containerized applications.
Related reading
- How to read files and stdout from a running Docker container
- How to rebuild and update a container without downtime with docker-compose?
- How to rebuild docker container in docker-compose.yml?
- How to recycle pods in Kubernetes
- How to push different local Git branches to Heroku/master
- How to re-commit a past commit if someone overwrote my commit
- How to redirect docker container logs to a single file?
- How to reduce the size of RHEL/Centos/Fedora Docker image

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.