Example blog

How to successfully connect to Docker Hub from the command line interface

If you’re having trouble signing into Docker Hub from the CLI, Jack Wallen has the fix for you.

Image: Docker

On several occasions I have encountered cases where, while trying to remove images from Docker Hub, I have been greeted with an authentication error. This issue arose when Docker Hub changed its login requirements, which was a necessary step forward in the constant threat of cybersecurity breaches.

However, this change has left many users scratching their heads, unsure of how to interact with the service. Fortunately, Docker Hub has taken this into account and made it easier for users to authenticate, so they can pull these images at will.

How do you manage the authentication process? I will show you.

SEE: The Best Programming Languages ​​To Learn – And The Worst (TechRepublic Premium)

What you will need

For this to work, you will need Docker up and running on a machine and a Docker Hub account.

How to create an access token

The first thing you need to do is create a Docker access token. To do this, log into your Docker Hub account and click on your profile picture in the upper right corner. Click Account Settings in the drop-down list, then click Security in the left navigation. In the window that appears, click New access token (Figure A).

Figure A

dockerhubautha.jpg

Creation of a personal access token on Docker Hub.

When prompted, give the new token a name (Number B).

Number B

dockerhubauthb.jpg

Give a name to the new Docker Hub personal access token.

Enter a new name for the token and click Create.

When the new pop-up appears, make sure to copy the new access token to your clipboard by clicking Copy and Close (Figure C).

Figure C

dockerhubauthc.jpg

Your new Docker Hub access token has been generated.

How to use your personal access token

Usually you can just unroll an image with the command:

docker pull IMAGE

Where IMAGE is the name of the image you want to extract. When you get an authentication error (which will prevent the image from downloading), you need to inform Docker Hub of your username and access token.

Before doing this, you need to issue the logout command in Docker CLI. The reason is that Docker may have cached your previous login credentials and will not accept the new access token. This has tripped me up before and the only way to get around this is to issue the command first:

docker logout

Once you have successfully logged out, you can then log in with the command:

docker login --username USER

Where USER is your Docker Hub username.

You will then be prompted to enter your Docker Hub access token. Paste the token into the CLI prompt and you will be logged into your Docker Hub account and should be able to fetch images at will.

Finally, if you’re still having issues, make sure you’re running the latest version of Docker on your system (be it Docker, docker-ce, etc.). An outdated version of the Docker engine can cause issues with Docker Hub authentication.

Subscribe to TechRepublic How to Make Technology Work on YouTube for all the latest technical advice for professionals at Jack Wallen’s business.

Also look


Source link