×
☰ See All Chapters

Docker ARG vs ENV command

docker-arg-vs-env-command-0

ARG

ENV

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

The ENV command sets environment variables within the image both when it is built and when it is executed.

Cannot be overridden.

Can be overridden when you launch your image. Values set from docker run command overrides the values set from dockerfile.

Can be set only through dockerfile.

Can be set from dockerfile, docker run command, env file.

Example:

FROM openjdk:13-jdk-alpine

ARG JAR_FILE=target/*.jar

COPY ${JAR_FILE} app.jar

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

Example:

FROM openjdk:13-jdk-alpine

ARG SOURCE_FILE=target/*.jar

ENV JAR_FILE app.jar

ENV DEBUG_LVL ERROR

ENV LOG_DIR=/app/log/

COPY ${SOURCE_FILE} ${JAR_FILE}

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

 

 


All Chapters
Author