How to use environment variables in docker.env file?

I have a folder with a cache, and the path is stored in an environment variable: $LOCAL_CACHE (export LOCAL_CACHE=/home/me/path/to/any/cache/folder)

Now I want to add some additional folders to the .env file:

My .env file is:

LOCAL_COMPOSER_DIR=${LOCAL_CACHE}/composer
LOCAL_NPM_DIR=${LOCAL_CACHE}/npm
LOCAL_BOWER_DIR=${LOCAL_CACHE}/bower

My docker_compose.yml looks like this:

version: '2'
services:
  composer:
    env_file: .env
    image: composer/composer
    volumes:
      - ./src:${APP_ROOT}
      - ${LOCAL_COMPOSER_DIR}:/composer
    working_dir: ${APP_ROOT}

When I start the service using docker-compose run composer instal. ..., it stops with the following error:ERROR: Named volume "$LOCAL_CACHE"/composer":/composer:rw" is used in service "composer" but no declaration was found in the volumes section.

I'm not sure, but the .env file does not seem to support the use of variables.

+5
source share
1 answer

Yes. .envYou cannot use variables in a file . Suddenly, but true. Actual for docker is version 1.8.

But you can use variables in the file docker-compose.yml, for example

volumes:
  - ${LOCAL_COMPOSER_DIR}/${CACHE_DIR}:/composer/${CACHE_DIR}

.

0

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


All Articles