Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inject AWS Codebuild Environment Variables into Dockerfile

Is there a way to pass AWS Codebuild environment variables into a Dockerfile? I'd like to be able to pull from ECR like this:

FROM $My_AWS_ACCOUNT.dkr.ecr.us-east-1.amazonaws.com/someimage:latest

Where $My_AWS_ACCOUNT references an environment variables within my codebuild project.

like image 401
pelican Avatar asked Jul 27 '26 13:07

pelican


1 Answers

Yes, you can use FROM ${My_AWS_ACCOUNT}.xxx. My_AWS_ACCOUNT should be passed as an argument to the docker build. This is how I would do it:

ARG My_AWS_ACCOUNT=SOME_DEFAULT_IMAGE FROM ${My_AWS_ACCOUNT}.xxx

When you build: docker build --build-arg My_AWS_ACCOUNT=${My_AWS_ACCOUNT}

like image 55
abelgana Avatar answered Jul 30 '26 03:07

abelgana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!