Passing build arguments to Dockerfile and converting them as environment variables

tech kamar
Feb 13, 2025

Imagine you are building a dockerfile and you need to control the build process using an ENV variable which you pass from outside during the build process.

In our case, the variable is MODE. MODE can have 2 values DEV and PROD. By Default we need the value to be DEV

The dockerfile for thesame is given belwo

Dockerfile

ARG MODE=DEV
ENV MODE=$MODE

Now to pass the value during build process use the

docker build --build-arg MODE=PROD -t test-docker-image .

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response