DEV Community

Cover image for Whats the difference between Args and Env in Docker
Mohamad Lawand
Mohamad Lawand

Posted on

Whats the difference between Args and Env in Docker

In this article we are going to discuss what's the difference between Args and Env within docker

You can watch the full video on YouTube

You can find the source code on github:
https://github.com/mohamadlawand087/v5-dockerComposeAspNetCpre

When you are creating your docker file to containerise your application often you want to pass arguments to your docker image and to your container but this can get a bit confusing if you are just starting out with Docker and containerisation.

Let us see how we can break this down

ARG - Build time var

Passing arguments to our docker image at build time we utilise ARG. ARG is only available during the build of a docker image. Once the image is build we cannot utilise ARG.

When utilising ARG it is advisable not to pass sensitive data as by using the following command

docker history
Enter fullscreen mode Exit fullscreen mode

We can see the args that was passed to build the image

ENV - All around Var

Unlike the ARG var, ENV is available to both the container and the image. The ENV can be overriden while starting a container

Image description

Top comments (0)