Reputation: 204
Docker Compose
can't use variables from .env
in docker-compose.yml
. .env
located in the same directory as docker-compose.yml
.
.env:
port:3306
docker-compose.yml:
ports:
- ${port}:${port}
The documentation shows exactly the same example and says that it works
web:
image: "webapp:${TAG}"
I have error while executing docker-compose up
WARNING: The port variable is not set. Defaulting to a blank string.
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.mariadb.ports is invalid: Invalid port ":", should be [[remote_ip:]remote_port[-remote_port]:]port[/protocol]
How to fix it?
Upvotes: 1
Views: 466
Reputation: 9619
From https://docs.docker.com/compose/env-file/:
Syntax rules
These syntax rules apply to the .env file:
- Compose expects each line in an env file to be in VAR=VAL format.
- Lines beginning with # are processed as comments and ignored.
- Blank lines are ignored.
- There is no special handling of quotation marks. This means that they are part of the VAL.
in .env
, use =
instead of :
Upvotes: 1