Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment Variable in docker compose

I wanted to create a docker-compose file, but the following seems to fail:

...
services:
  test:
    ...
    volumes:
      - ${FOO}:/bar
...

I've read that environment variables are not evaluated in keys, only in values. But since the $FOO is a value, I thought this would work?

like image 731
KillPinguin Avatar asked Dec 06 '25 18:12

KillPinguin


1 Answers

This works. You have to declare FOO somewhere to get the result. Following code will work:

caller.sh

#!/bin/sh
export FOO=/home
docker-compose up
like image 68
grapes Avatar answered Dec 09 '25 13:12

grapes