Skip to content

Unable to Log in to Docker Using Environment Variables with Bitbucket Runner on EC2 Instance

0

I have hosted my Bitbucket runner on an EC2 instance and am trying to log in to Docker using environment variables. However, the login fails when using environment variables. If I hardcode the values directly into the script, the login works perfectly. Here is the relevant part of my script:

Attempt to log in using environment variables (this fails)

docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD

Hardcoded values (this works)

docker login -u my_username -p my_password

I have confirmed that the environment variables are set correctly in my script. What could be causing the login to fail when using environment variables, and how can I resolve this issue?

Thanks in advance for your help!

asked 2 years ago382 views
2 Answers
0
Accepted Answer

Hello.

It may not matter much, but why not try surrounding the variable with double quotes?
I can't say for sure because I haven't seen the error message, but the variables may not be expanded properly.

docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"
EXPERT
answered 2 years ago
0

IMHO Secrets Manager would be a better option.

AWS Secrets Manager AWS System Manager Parameter Store

https://docs.aws.amazon.com/secretsmanager/latest/userguide/retrieving-secrets.html

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.