Table of Contents
What is a docker compose env file
You can create the docker compose env file by using a text editor. To start with the example one, go to http://docs.docker.com/compose/examples/ which will include an example of docker compose env file and instructions on how to use it.
Default options and environment variables are not set in the Docker Compose file. The below is an example of how you could set some useful variables in the Docker Compose file:
version: ‘2’ services: elasticsearch: image: ‘elasticsearch:5.0.1’ environment: – cluster.name=dockercompose_cluster – bootstrap.memory_lock=true – “ES_JAVA_OPTS=-Xms512m -Xmx512m” uwc-dir: ‘Docker Compose Environment’ ports: – 9200:9200
The above example create a docker compose env file from a Docker Compose file, which will appear to have environment variables in it. You can set these variables in the environment section. We got the example by going to http://docs.docker.com/compose/examples/
Fixed options on the docker compose file

How to create a docker compose env file
With the example above, you do not have to type in each and every word. You can copy and paste the variables from Docker’s site. You’ll get a much shorter command to add and remove environments.
Let’s start by creating our .env file. Open your preferred text editor, then paste the following in:
DOCKER_CMD=”docker-compose up -d –force-remove” DOCKER_COMPOSE_USER=”docker” DOCKER_COMPOSE_EMAIL=”[email protected]”
Now, type your commands in precisely as they appear above. Keep an eye on your editor and press tab to complete each line. Once you’re finished, save the file and open it with this command:
sudo vim .env
You’ll see something that looks like the following:
DOCKER_CMD=”docker-compose up -d –force-remove” DOCKER_COMPOSE_USER=”docker” DOCKER_COMPOSE_EMAIL=”[email protected]”
You can now run the docker-compose commands by typing “docker-compose [tab]” and hitting enter to autocomplete.
If you made a mistake, you can always rollback to the previous version of your .env file by typing:

What to include in your docker compose env file
For the environment variables, you may or may not include the following. If they are already included in the configuration file, they may be omitted. They may also already be set.
Either way, have a read and see if you need to make any changes!
## DOCKER ENVIRONMENT VARIABLES ##
.
.
.

Examples of docker compose env files
For our example, we will create a Dockerfile file to build the image using Ubuntu. The Dockerfile file includes instructions on how to install git, node, and other prerequisites. In addition to the steps in the example Compose file, please remember that you need to add a “build” and “run” section in your Dockerfile. Here is an example:
#dockerfile FROM ubuntu:16.04 #add node RUN apt-get update && apt-get install -y nodejs #add git RUN apt-get update && apt-get install -y git 1 2 3 4 5 6 7 8 9 10 11 12 13 #dockerfile FROM ubuntu : 16.04 #add node RUN apt – get update & amp ; & amp ; apt – get install – y nodejs #add git RUN apt – get update & amp ; & amp ; apt – get install – y git
The last step is to compile the Dockerfile into an image using the following command: