docker login 登录harbor报错:Error response from daemon: Get ...: unauthorized: authentication required

docker login 登录harbor报错:Error response from daemon: Get “http://harbor.test.cn/v2/”: unauthorized: authentication required

1. Problem background

  • The harbor enterprise mirror warehouse was created during the test, but was rejected when logging inunauthorized: authentication required
docker login -uadmin -pasdf harbor.test.cn
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get "http://harbor.test.cn/v2/": unauthorized: authentication required

image-20230309193108039

2. Troubleshoot ideas

  • Is the local hosts file wrong? ? ?
  • The /etc/docker/daemon.json file is wrong? ? ?
  • Harbor.yml file modification problem? ? ?
  • After modifying daemon.json, the docker service is not restarted? ? ?
  • Docker container failed to start? ? ?
  • docker is not compatible with docker-compose or harbor is not compatible with docker-compose version? ? ?

3. Solution

All the above problems have been checked and found to be normal

3.1 First attempt

  • I try to log in from the webpage, and enter the password configured in harbor directly on the webpage to log in

image-20230309194019319

I found that I can’t even log in to the webpage. This is the password problem, and then I try the following operations

1. Delete all containers, and call the ./install.sh file to install –> password login or error

2. Delete all containers, delete the harbor.tar.gz compressed package, re-upload, decompress and install –> password login or error

After excluding the problem of the installation package and docker service version, I suspect that there is a local cache, even if I delete all the containers, it is useless

3.2 Check harbor's script

With a skeptical mentality, I checked the docker-compose.yml file automatically generated by the install.sh script, and found that a large number of volume data volumes were created in it

  • storage log

image-20230309194826063

  • stored in the database

image-20230309195002673

  • store cache redis

image-20230309195035490

  • Other volumes

image-20230309195110549

image-20230309195124018

  • All volumes in the /data directory

image-20230309195208753

I tested to delete all the containers and found that these directories still exist. Even if I delete the harbor compressed package and install it again, these directories will still be called

The login password information is stored in the database

3.3 Problem solving

Once the problem is found, the solution becomes easy

3.3.1 Method 1

The fastest way is to delete the /data directory and all containers, exclude occupied ports, delete docker-compose.yml, and run the install.sh script to create

3.3.2 Method 2

If in the production environment, a large number of images have been stored in harbor and the container cannot be deleted, you can try this method

  • View the created container

image-20230309195844560

  • Log in to the harbor-db container and log in to the psql database. The default password is root123

image-20230309200322697

  • Switch to the registry database and view the table information inside

image-20230309200602599

  • Find the harbor_user table -> the login information is stored in it

image-20230309200641382

  • See how passwords are encrypted

image-20230309200737885

  • Change the login password to the initial password Harbor12345
update harbor_user set password='c999cbeae74a90282c8fa7c48894fb00', salt='nmgxu7a5ozddr0z6ov4k4f7dgnpbvqky' where username='admin';

image-20230309200847717

  • Login successfully

image-20230309201201291

image-20230309201131745

Guess you like

Origin blog.csdn.net/m0_49562857/article/details/129430323