Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile define multiple ARG arguments in a single line

Right now I am defining ARGs in my Dockerfile like this:

ARG CDN_ENDPOINT
ARG AWS_S3_BUCKET

Is there a way to define them in a single line similar to ENV to avoid creating extra layers in docker image like this:

ENV CDN_ENDPOINT=endpoint \
    AWS_S3_BUCKET=bucket
like image 850
Muhammad Abdul Raheem Avatar asked Dec 09 '19 12:12

Muhammad Abdul Raheem


2 Answers

After testing this by creating the ARGs similar to ENV like this:

ARG CDN_ENDPOINT \
    AWS_S3_BUCKET

I got this error:

ARG requires exactly one argument definition

So judging from that, the ARG command only allows one argument. So its impossible to define multiple ARGs in a single line inside dockerfile.

like image 172
Muhammad Abdul Raheem Avatar answered Sep 17 '22 19:09

Muhammad Abdul Raheem


To achieve what you want you have to do this:

in your Dockerfile define the ARG variables you need with a default value (so, in case you don't pass it it can still work):

ARG P_TAG=8-jdk
FROM openjdk:${P_TAG}

ARG P_VERSION="1.22.2-stable"

ENV TAG=${P_TAG}
ENV VERSION=${P_VERSION}

RUN echo TAG=${TAG}
RUN echo VERSION=${VERSION}

Then your build line should go like this:

docker build --build-arg P_TAG=11-jdk --build-arg P_VERSION=2.0.4-stable

You need to be sure that your dockerfile contains as ARG all the variables you need to pass.

like image 44
René Lazo Avatar answered Sep 16 '22 19:09

René Lazo