How to use a --build-arg parameter before FROM in a Dockerfile

0 votes

I'm working on AWS ECR for hosting my project images. I'm using the FROM parameter to dynamically set the Dockerfile according to --build-arg input in the CLI.

$ docker build --build-args region=eu-north-1 .

// Dockerfile
FROM aws.ecr.huge.url.${region}/repo:php-apache
WORKDIR /var/www
RUN echo "@@@"

Here I want to replace the ${region} but that never happens and an error show up. But, when I run echo ${region} it works leading me to believe the problem is in FROM instruction

Can someone please help??

Apr 12, 2018 in Docker by Atul
• 10,240 points
1,532 views

1 answer to this question.

0 votes

In the earlier docker version this wasn't possible, but now after the introdiction of multi-stage builds, the user can provide an argument before FROM. SOmething like this:

# default to eu-north-1
ARG region=eu-north-1
FROM aws.ecr.huge.url.${region}/repo:php-apache

Also, the arguments are namespaced. Therefore, when you define them before a FROM line, they're available to FROM until the end of stage. To use args in multiple namespaces, you'll have to define it every time.

answered Apr 12, 2018 by ajs3033
• 7,300 points

Related Questions In Docker

0 votes
1 answer

How to add a comment in a Dockerfile?

Here is what you have to do. Try ...READ MORE

answered Nov 13, 2018 in Docker by Damon Salvatore
• 5,980 points
8,897 views
+1 vote
0 answers

How can I map a docker location to my Jenkins workspace so that I can use the files in my Jenkins

Hey guys, I was trying to execute few ...READ MORE

Feb 25, 2020 in Docker by dineshkumar
• 130 points
4,637 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Unable to switch filesystem to overlay in Docker in Ubuntu.

From the official docs: https://docs.docker.com/engine/userguide/storagedriver/overlayfs-driver/#configure-docker-with-the-overlayoverlay2-storage-driver To configure Docker ...READ MORE

answered Jul 18, 2018 in Docker by ajs3033
• 7,300 points
2,513 views
0 votes
1 answer

How do I know which datastore indexes are in error?

There was no public API for managing ...READ MORE

answered Jul 27, 2018 in Docker by ajs3033
• 7,300 points
546 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP