docker-compose environment not getting set

Viewed 145

I'm having a problem with docker-compose : the enviroment part doesn't seem to work anymore on one server whereas the same thing works on other servers.

On the designated server, with this docker-compose :

version: '3'
services:
  test:
    image: 'busybox'
    command: env
    environment:
      - HELLO=WORLD

Running docker-compose up outputs this :

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=8d4af1fcbe88
HOME=/root

No trace of the environment variable HELLO

I tried running

docker run -e test=plop busybox env

It works and outputs

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=5880600fbb99
test=plop
HOME=/root

I tried using the latest docker-compose version on github but it changes nothing.

The same problem appears when using .env files.

Does anyone has any idea about what could be happening here ?

Edit: To be clear, I already ran this docker-compose on other servers and it works as intended, i was wondering if some people could help me debug this "bug". Here is a walkthrough that explains what I did :

/tmp/test$ curl -SsL "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o docker-compose
/tmp/test$ ls -a
.  ..  docker-compose  docker-compose.yml
/tmp/test$ cat docker-compose.yml
version: '3'
services:
  test:
    image: 'busybox'
    command: env
    environment:
      - HELLO=WORLD
/tmp/test$ sudo ./docker-compose down
Removing network test_default
WARNING: Network test_default not found.
/tmp/test$ sudo ./docker-compose up -d
Creating network "test_default" with the default driver
Creating test_test_1 ... done
/tmp/test$ sudo docker logs test_test_1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=b68e605e609d
HOME=/root
2 Answers

I tried the exact docker-compose.yml and I am getting the expected output. Please check the below logs.

$ cat docker-compose.yml 
version: '3'
services:
  test:
    image: 'busybox'
    command: env
    environment:
      - HELLO=WORLD

$ docker-compose up
Creating network "cwa-base-webpack_default" with the default driver
Creating test_1 ... done
Attaching to test_1
test_1  | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
test_1  | HOSTNAME=00bd78e58400
test_1  | HELLO=WORLD
test_1  | HOME=/root
test_1 exited with code 0

Few points which you can check:-

  • Run docker-compose down before you run docker-compose up just to rule out any previous deployments.
  • Make sure you are using the correct docker-compose.yml file i.e. you are in the right directory and using the default file.

In the end, the problem was solved by updating docker. 18.09.8 did the trick. A little weird because docker worked with environment variables. I guess it was the interaction between the two. Thank you for helping anyway !

Related