Set up container runtime variable

As the image command is only run during build time, however, while running the container, we might need to access some environment or configuration variable. here is the workaround:

ARG variable=unknown ## Build time
ENV variable=${variable} ## Run time

Then to pass in the arg,

docker build--build-arg version=0.0.1

for docker-compose, then

  image: image
  restart: always
    context: dockerfile
      version: ${version} ## alternatively, default a value here

for docker-compose,


can be used to retrieve the environment variable

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s