How To Pass Environment Info During Docker Builds

A detailed guide to Docker’s ENV and ARG with examples

Photo by mostafa meraji on Unsplash

Sometimes we have to pass environment information to the running container or during the image build. We use both ENV and ARG instructions to achieve that. Let’s create one simple nodejs project with express as an example.

Example Project

ARG Instruction

ENV Instruction

Difference Between ENV and ARG

Pass Info with ENV and ARG

Summary

Conclusion

Tip: Optimize teamwork by using the right tools for code-sharing

Use Bit to share, install and collaborate on individual JS modules and UI components. Stop wasting time configuring packages, managing multiple repositories or maintaining cumbersome monorepos.

Components with Bit: Easily share across projects as a team

Example Project

This is a simple node js express server serving at the port 3080 and we have a Dockerfile which builds the image.



git clone //clone the projectgit clone https://github.com/bbachi/docker-environment-read.git //install and run the project

npm install

npm start

We can build the docker image with this command docker build -t nodejs-sever . Once built we can see the images with this command docker images

docker images