Declaring variables in docker-compose

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

The idea was to pass the Docker image tag to the image as an environment variable. However, I do not want to change the version number in the image and in the ENV variable all the time.

Example:

version: "3"

VERSION=0.2.3

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

Can variables be declared to update all values ​​together, or is there any other solution?

+4
source share
1 answer

You cannot define $VERSIONinside compose yml, but you can define it in a file .envor directly in your environment where you run the command docker-compose. eg:.

VERSION=0.2.3 docker-compose up -d
+4
source

Source: https://habr.com/ru/post/1691594/


All Articles