- Docker installed on your machine. Install Docker
- Run a Local Docker Registry
Start a local Docker registry container:
docker run -d -p 5000:5000 --name registry registry:latest
- Tag Your Docker Image
Tag the image you want to push to your local registry:
docker tag <source-image> localhost:5000/<desired-image-name>:<tag>
Replace <source-image>
with the name of your local image, <desired-image-name>
with the name you want to give the image in your local registry, and <tag>
with the version tag (e.g., latest).
Example:
docker tag my-app:latest localhost:5000/my-app:latest
- Push the Image to the Local Registry
Push the tagged image to your local registry:
docker push localhost:5000/<desired-image-name>:<tag>
Example:
docker push localhost:5000/my-app:latest
-
Configure Docker to Use HTTP for Your Registry (Optional):
Docker uses HTTPS by default for security reasons. To push to an HTTP registry, you need to explicitly tell Docker to allow insecure registries.
Open the Docker daemon configuration file in a text editor:
sudo nano /etc/docker/daemon.json
Add the insecure-registries entry:
{
"insecure-registries": ["localhost:5000"]
}
Save the file and exit the editor.
- Verify the Image in the Local Registry
You can verify that the image is successfully pushed by listing the images in the registry:
curl -X GET http://localhost:5000/v2/_catalog
To see the tags for a specific repository, use:
curl -X GET http://localhost:5000/v2/<desired-image-name>/tags/list
Example:
curl -X GET http://localhost:5000/v2/my-app/tags/list
- Pull the Image from the Local Registry
To pull the image from your local registry to another machine (or the same machine), use the following command:
docker pull localhost:5000/<desired-image-name>:<tag>
Example:
docker pull localhost:5000/my-app:latest
- Push the Image from Jenkins to Docker Local Registry (optional)
When you are pushing an image from the Jenkins pipeline you need to give access to docker demon.
sudo usermod -aG docker jenkins
Then restart both jenkins and docker
sudo systemctl restart jenkins
sudo systemctl restart docker
Here's a full example to illustrate the process:
-
Build a Docker image:
docker build -t my-app:latest .
-
Tag the Docker image:
docker tag my-app:latest localhost:5000/my-app:latest
-
Push the image to the local registry:
docker push localhost:5000/my-app:latest
-
Verify the image is in the registry:
curl -X GET http://localhost:5000/v2/_catalog curl -X GET http://localhost:5000/v2/my-app/tags/list
-
Pull the image from the local registry:
docker pull localhost:5000/my-app:latest
By following these steps, you can easily push and pull Docker images to and from your local Docker registry.