Using environmental variables

In this section, we will cover the very powerful environmental variables (ENVs), as you will be seeing a lot of them. You can use ENVs for a lot of things in your Dockerfile. If you are familiar with coding, these will probably be familiar to you.

For others like myself, at first they seemed intimidating, but don't get discouraged. They will become a great resource once you get the hang of them. They can be used to set information when running the container, which means that you don't have to go and update lots of the commands in your Dockerfile or in scripts that you run on the server.

To use ENVs in your Dockerfile, you can use the ENV instruction. The structure of the ENV instruction is as follows:

ENV <key> ...

Get Mastering Docker - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.