How does Docker connect to the local private server Harbor to push images, view images, and download images?

1. Basic environment

  • win/mac/linux
  • Docker installed
  • Private server Harbor

Docker

Docker Chinese website
Docker official website
Download and install Docker
Please add image description

Harbor

Harbor GitHub
Harbor official address
Download and install Harbor (for testing, it is recommended to use the Docker image to start Harbor to reduce environmental problems)

2. Configuration process

Login to Harbor

After startup, visit Harbor's page.
Log in.
Please add image description
After entering, it will be displayed.
Remember these key information (different for everyone): address (172.16.1.77), account number (xxxxx), password (xxxxxx)
Please add image description

Configure Docker

Open the Docker settings
(generally /etc/docker/daemon.json for non-visual Docker),
Please add image description
modify the configuration file,
and configure the private server address to join.insecure-registries
Below is my configuration reference

{
    
    
  "builder": {
    
    
    "gc": {
    
    
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "debug": true,
  "experimental": true,
  "features": {
    
    
    "buildkit": false
  },
  "insecure-registries": [
    "172.16.1.77"
  ]
}

After saving andRestartdocker

Configure connection

After configuring the private server, you need to let docker log in to the private server
and open the Shell for execution.

docker login 172.16.1.77

Prompt to enter account and password to display successful login.

3.Operation process

Download image

Randomly download a Docker image

docker pull nginx

Please add image description
Here are the downloaded results:

docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
934ce60d1040: Pull complete
238b470e100d: Pull complete
fd4ff90344fc: Pull complete
7be7509b8147: Pull complete
fc07d3e6158f: Pull complete
d44fa61c1ffa: Pull complete
Digest: sha256:b8f2383a95879e1ae064940d9a200f67a6c79e710ed82ac42263397367e7cc4e
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

~ took 25.6s

Packaging image

(You can also use the image you just downloaded to push it directly to the private server Harbor. This assumes we have modified something or have our own image.)
Package a new Nginx image through the Dockerfile
and push it to Harbor.

Create a new file Dockerfile

FROM nginx
MAINTAINER wzk
WORKDIR /usr/share/nginx/html
EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]

Package the image

docker build -t 172.16.1.77/alibaba-cloud/nginx .

-trefer to tag, label

  • 172.16.1.77 is the address of harbor
  • alibaba-cloud is a folder (this is optional)
  • nginx is the image name
  • . The last dot refers to the Dockerfile in the current directory.
    Please add image description

Push image

View current image

docker images

Please add image description
Push to harbor

docker push 172.16.1.77/alibaba-cloud/nginx

Please add image description
Push completed

Guess you like

Origin blog.csdn.net/w776341482/article/details/128849970