Skip to content

Latest commit

 

History

History
148 lines (77 loc) · 3.13 KB

docker_local_registory.md

File metadata and controls

148 lines (77 loc) · 3.13 KB

Using Docker Local Registry to Push Images

Prerequisites

Steps

  1. Run a Local Docker Registry

Start a local Docker registry container:

docker run -d -p 5000:5000 --name registry registry:latest
  1. 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
  1. 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
  1. 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.

  1. 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
  1. 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
  1. 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

Full Example

Here's a full example to illustrate the process:

  1. Build a Docker image:

    docker build -t my-app:latest .
  2. Tag the Docker image:

    docker tag my-app:latest localhost:5000/my-app:latest
  3. Push the image to the local registry:

    docker push localhost:5000/my-app:latest
  4. 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
  5. 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.