“This is the 7th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

What is a Docker repository

  • Docker repository is a cloud environment where Docker image is stored and Docker pull method is downloaded

Docker pull usage can be seen in the first docker article series:

  • Docker warehouse is divided into public warehouse and private warehouse.
    • Public repository refers to Docker Hub(official) and other open for users to use, allowing users to manage images.
    • A private repository is a cloud environment that is built by users to store images.

How to set up an unauthenticated private warehouse

The main steps are as follows:

  • Step 1: Install Docker on the server where you want to build the warehouse.

  • Step 2: On the server, download the Registry repository from the Docker Hub

    docker pull registry

  • Step 3: On the server, start the repository

    docker run -d -ti --restart always\
    		--name my-registry\
    		-p 8000:5000\
    		-v /my-registry/registry:/var/lib/registry\
     	registry
    Copy the code

    Note: The internal open port of Registry is 5000. By default, the image is stored in /var/lib/registry, so that if the container is deleted, the image stored in the container will be lost.

  • Curl server IP:8000/v2_catalog (Note that port 8000 access is enabled)

Upload and download images to a private repository

  • Step 1: Rename the image to be uploaded using the Docker tag

    Docker Tag IMAGE Server IP address: port /IMAGE_NAME

  • Step 2: Upload the newly renamed image using docker Push

    Docker push server IP: port /IMAGE_NAME

  • Note: must be renamed to server IP: port /IMAGE_NAME

    If push has an HTTPS error, you need to add: “insecure-registries” :[” server IP: port “] to /etc/docker-daemon. json.

    Then restart docker.

Set up a private warehouse with authentication

On the server:

  • Step 1: Delete the previously created unauthenticated warehouse container

      docker rm -f my-registry
    Copy the code
  • Step 2: Create a file to store the authentication user name and password:

    mkdir /my-registry/auth -p

  • Step 3: Create a password verification file. Notice the USERNAME and PASSWORD are replaced with the specified USERNAME and PASSWORD

    docker run --entrypoint htpasswd registry -Bbn USERNAME PASSWORD > /my-registry/auth/htpasswd
    Copy the code
  • Step 4: Restart the warehouse image

    docker run -d -p 8000:5000 --restart=always --name docker-registry \
    -v /my-registry/registry:/var/lib/registry \
    -v /my-registry/auth:/auth \
    -e "REGISTRY_AUTH=htpasswd" \
    -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
    -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \
    registry
    Copy the code

Private warehouse with authentication, how to upload, download image

On a local machine:

  • Step 1: Log in to the server first

    Docker login -u username -p password Server IP address :8000Copy the code
  • Step 2: Then run the pull or push command. For details, see Upload/download for an unauthenticated repository

  • Step 3: After the operation, you can log out

    Docker logout server IP:8000

If you want to view an existing image in the repository, HTTP authentication is required. The server IP:8000/v2/_catalog can be accessed directly from the browser