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 in
unauthorized: 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
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
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
- stored in the database
- store cache redis
- Other volumes
- All volumes in the /data directory
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
- Log in to the harbor-db container and log in to the psql database. The default password is root123
- Switch to the registry database and view the table information inside
- Find the harbor_user table -> the login information is stored in it
- See how passwords are encrypted
- Change the login password to the initial password Harbor12345
update harbor_user set password='c999cbeae74a90282c8fa7c48894fb00', salt='nmgxu7a5ozddr0z6ov4k4f7dgnpbvqky' where username='admin';
- Login successfully