×
☰ See All Chapters

Docker ARG command

Docker ARG command is used to declare the variable with value in dockerfile. If same value is used multiple times in dockerfile and if you want to change the value, you should change it from all the places. Hence if some value is repeatedly used in dockerfile you can declare a variable for it and use that variable instead of that value. If you now have to change the value, change it in one place.

Syntax of ARG command

ARG VARIABLE_NAME=value

Expression to use ARG variable in other commands

${VARIABLE_NAME}

OR

$VARIABLE_NAME

While accessing the variable using braces is optional.

Docker ARG command Example

FROM openjdk:13-jdk-alpine

ARG JAR_FILE=target/*.jar

COPY ${JAR_FILE} app.jar

ENTRYPOINT ["java","-jar","/app.jar"]

Variables set using ARG command will be available only till image is built. Image cannot use these variables when it is run.

 


All Chapters
Author