Docker compose with environment file gives unexpected results

Hello everyone, I’ll show you the situation right away.

Here is the my scenario

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.4 LTS
Release:	22.04
Codename:	jammy
$ 
$ docker compose version
Docker Compose version v2.29.0
$ 

$ pwd
/tmp/tmp.B1ybwh2RVZ
$ 
$ tree
.
├── docker-compose.yml
└── tmp.env

0 directories, 2 files
$ 
$ cat tmp.env 
COMPOSER_VENDOR_DIR=$HOME/build/$PWD/vendor
$ 
$ cat docker-compose.yml 
services:
    test:
        image: bash
        volumes:
            - type: bind
              source: ${COMPOSER_VENDOR_DIR-vendor}
              target: /app/vendor
        env_file:
          - path: tmp.env
            required: true
volumes:
    vendor:
$ 
$ docker compose config
name: tmpb1ybwh2rvz
services:
  test:
    environment:
      COMPOSER_VENDOR_DIR: /home/MY_NAME/build//tmp/tmp.B1ybwh2RVZ/vendor
      DISABLE_FOLLOW: "1"
    image: bash
    networks:
      default: null
    volumes:
      - type: bind
        source: /tmp/tmp.B1ybwh2RVZ/vendor
        target: /app/vendor
networks:
  default:
    name: tmpb1ybwh2rvz_default

I’m highlighting a couple of lines

$ docker compose config | grep /tmp/tmp
      COMPOSER_VENDOR_DIR: /home/MY_NAME/build//tmp/tmp.B1ybwh2RVZ/vendor
        source: /tmp/tmp.B1ybwh2RVZ/vendor

mmmh… but I expected the fields (COMPOSER_VENDOR_DIR and source) to have the same value, that is

      COMPOSER_VENDOR_DIR: /home/MY_NAME/build//tmp/tmp.B1ybwh2RVZ/vendor
        source: /home/MY_NAME/build//tmp/tmp.B1ybwh2RVZ/vendor

What’s wrong?

Nothinggggggggggggg?

Variables are interpolated from .env, not tmp.env. The env_file property does not affect it.

You can do docker compose --env-file tmp.env config

1 Like