Override ENV variables inside Docker Compose

Hey, I have those ENV variables for my docker compose config. There's one problem, inside docker I have to specific DB_HOST {container_name}, so I've tried to override it.
DB_HOST=localhost
DB_USER=
DB_PASSWORD=
DB_NAME=
DB_PORT=

DATABASE_URL=mysql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
DB_HOST=localhost
DB_USER=
DB_PASSWORD=
DB_NAME=
DB_PORT=

DATABASE_URL=mysql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
env_file:
- .env
environment:
DB_HOST: mysql # Rewrite the `localhost` host, but this won't override the `DATABASE_URL` ENV
env_file:
- .env
environment:
DB_HOST: mysql # Rewrite the `localhost` host, but this won't override the `DATABASE_URL` ENV
1 Reply
venus
venus2y ago
When I try to log the ENV vars using - command: env, then the ENV var change won't get affected
DATABASE_URL=mysql://<user>:<pw>@mysql:<port>/<db>
DB_NAME=
SERVER_URL=
DB_PASSWORD=
DB_HOST=
DB_USER=
DATABASE_URL=mysql://<user>:<pw>@mysql:<port>/<db>
DB_NAME=
SERVER_URL=
DB_PASSWORD=
DB_HOST=
DB_USER=
Want results from more Discord servers?
Add your server