How do I set environment variables during the build in docker

0 votes

I've tried unsuccessfully to set environment variables in a Docker container during the build. Using the run command to set them works, but I need to do it during the build.

Here's dockerfile

FROM ubuntu:latest
ARG TEST_ENV=something

My build command

docker build -t --build-arg TEST_ENV="test" myimage .

My run command

docker run -dit myimage

Using below command to check available environment variables

docker exec containerid printenv

My result

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=e49c1abfd58b
TERM=xterm
no_proxy=*.local, 169.254/16
HOME=/root

TEST_ENV is not present here

May 10, 2022 in Docker by pranav
• 2,590 points

edited 4 days ago 94 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP