Use 1Password to manage a Docker Personal Access Token in WSL2
You can use 1Password to manage Docker Personal Access Tokens within Windows Subsystem for Linux. This improves security and efficiency.
Personal access tokens (PATs) provide a secure alternative to passwords for Docker CLI authentication without exposing your Docker Hub password. Setting this up in WSL2 with management from 1Password is a bit tricky, but doable. This article outlines the process.
This assumes that you have already installed the 1Password CLI in Windows and enabled it in WSL2.
Step 1: PAT Creation
Log into docker.com and create a Personal Access Token.
Step 2: Save the PAT into 1Password
Open 1Password and go to + New Item and choose “API Credentials”

Enter the PAT as the “credential”. Take a note of which vault this is saved to, as you will need it later. I am saving mine to “Personal”.

Step 3: Locate the OP file path
You will need to locate the path of the OP file from the 1Password CLI. To do this, open PowerShell and enter the following command:
(Get-Command op).Source
You will obtain a Windows file path similar to this:
C:\Users\<username>\AppData\Local\Microsoft\WinGet\Packages\AgileBits.1Password.CLI_Microsoft.Winget.Source_8wekyb3d8bbwe\.\op.exe
Step 4: Point WSL2 to the 1Password CLI
On the Linux command line in WSL2, enter the following commands:
mkdir -p ~/.local/bin
ln -s "/mnt/c/Users/<username>/AppData/Local/Microsoft/WinGet/Packages/AgileBits.1Password.CLI_Microsoft.Winget.Source_8wekyb3d8bbwe/op.exe" ~/.local/bin/op
Step 5: Add /.local/bin to Path
In WSL2, enter the following commands:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
hash -r
If everything is working, entering the command op --version should return a version number.
Step 6: Locate your PAT credential ID in 1Password
In WSL2, enter the following command to get the credential ID for your PAT:
op item list --categories "API Credential"
It should return a value like this:
ID TITLE VAULT EDITED
GfpRJR2G81VBTnr3FWUs Docker PAT Personal 14 minutes ago
Step 7: Link your 1Password credential to Docker
You will need to enter the following code into WSL2:
op read -n "op://<vault>/<id>/credential" | \
docker login -u <username> --password-stdin
Where:
vaultis your vault nameidis the credential ID numberusernameis your Docker username
So in this case, the correct code for me would be:
op read -n "op://Personal/GfpRJR2G81VBTnr3FWUs/credential" | \
docker login -u myusername --password-stdin
If this has worked, you should see Login Succeeded.
Step 8: Test
Enter the following command in WSL2 to log-in to Docker with 1Password using your PAT:
docker login
Comments
No comments have yet been submitted. Be the first!