In this section, we will:
Run the following command to prompt the user for Docker Hub credentials and store them in variables:
echo '
# Docker Hub Credentials
export DOCKER_USERNAME="'$(read -p "Enter Docker Hub username: " username; echo $username)'"
export DOCKER_TOKEN="'$(read -s -p "Enter Docker Hub token: " token; echo $token)'"' >> ~/.bashrc
source ~/.bashrc
:::alert{header=“Important” type=“warning”} When entering your Docker Hub token, the input will be hidden for security reasons. This is normal behavior - your token is being captured correctly even though you don’t see any characters on screen. Please type your token carefully and only press Enter once when complete to avoid multiple entries. :::
Let’s verify your credentials were captured correctly before attempting to log in:
# This will show only the first 4 characters of your token followed by asterisks
echo "Username: $DOCKER_USERNAME"
echo "Token: ${DOCKER_TOKEN:0:4}$(printf '%*s' $((${#DOCKER_TOKEN}-4)) | tr ' ' '*')"
:::alert{header=“Troubleshooting” type=“info”} If the username is incorrect or the token appears empty, you can reset them with these commands:
# Only run this if you need to reset your credentials
export DOCKER_USERNAME=$(read -p "Enter Docker Hub username: " username; echo $username)
export DOCKER_TOKEN=$(read -s -p "Enter Docker Hub token: " token; echo $token)
:::
Now, let’s log in to Docker Hub:
docker login -u $DOCKER_USERNAME -p $DOCKER_TOKEN
Instead of hardcoding credentials, we will store them securely in AWS Secrets Manager.
Create a secure AWS secret using the entered credentials:
aws secretsmanager create-secret --name dockerhub-credentials \
--description "Docker Hub credentials for AWS CodePipeline" \
--secret-string "{\"DOCKER_USERNAME\":\"$DOCKER_USERNAME\", \"DOCKER_TOKEN\":\"$DOCKER_TOKEN\"}"
✅ This command securely stores DOCKER_USERNAME
and DOCKER_TOKEN
in AWS Secrets Manager.
Run the following to confirm the secret exists:
aws secretsmanager list-secrets | grep dockerhub-credentials
To view the stored values (for debugging purposes only):
aws secretsmanager get-secret-value --secret-id dockerhub-credentials --query SecretString --output json
Now that credentials are securely stored: