Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring variables in docker-compose

I want to let my application know which image version it is running on.

The idea was to pass the Docker image tag into the image as an environment variable. However I don't want to change the version number in both the image line AND in the ENV variable line all the time.

Example:

version: "3"

VERSION=0.2.3

services:
  app:
    image: myimage:$VERSION
    environment:        
       - APPLICATION_VERSION:$VERSION

Is it possible to declare variables in order to update all values together or is there any other solution available?

like image 698
Marian Klühspies Avatar asked Jan 01 '18 21:01

Marian Klühspies


1 Answers

You cannot define $VERSION inside the docker-compose.yml.

You have two options for this:

  • define it in a .env file
  • send as a command line argument when you run the docker-compose command. e.g. VERSION=0.2.3 docker-compose up -d
like image 72
BMitch Avatar answered Oct 12 '22 14:10

BMitch