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
288 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,280 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,510 points
660 views
+4 votes
4 answers

How To Access a Service on Host From a Docker Container?

Adding to kalgi's answer, You can also ...READ MORE

answered Oct 16, 2018 in Docker by lina
• 8,110 points

edited Oct 16, 2018 by lina 4,291 views
0 votes
1 answer

How to run a docker command from inside the container?

You must have come across the /var/run/docker.sock file, ...READ MORE

answered Jun 28, 2018 in Docker by Sophie may
• 9,530 points
326 views
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,280 points
570 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,280 points
28 views