7

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

Now I want to append some additional folders inside my .env file:

My .env file:

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

My docker_compose.yml looks like that:

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 with docker-compose run composer instal. ... it stops with 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 shure but it seems, the .env file doesn't support the use of variables.

Kevin
  • 1,232
  • 10
  • 28

1 Answers1

0

Yes. Into .env file you can not use variables. Suddenly but true. Actual for docker compose version 1.8.

But you can use variables into docker-compose.yml file like

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

This answer suggest us another way.

Community
  • 1
  • 1
Bukharov Sergey
  • 9,767
  • 5
  • 39
  • 54
  • Sometimes you have different systems with different environment variables. My idea was, to normalize the environment variables inside the .env.DIST files and not inside the docker-compose.yml. – Kevin Feb 21 '17 at 14:36