I'm using a makefile to build my project and this is my file hierarchy:
➜ Inception git:(main) ✗ ls -l *
-rw-r--r-- 1 dcavalei dcavalei 258 Jan 6 16:34 Makefile
srcs:
total 28
drwxr-xr-x 5 dcavalei dcavalei 4096 Jan 6 11:45 .
drwxr-xr-x 7 dcavalei dcavalei 4096 Jan 6 17:21 ..
-rw-r--r-- 1 dcavalei dcavalei 631 Jan 6 17:02 docker-compose.yml
-rw-r--r-- 1 dcavalei dcavalei 123 Jan 6 15:49 .env
drwxr-xr-x 3 dcavalei dcavalei 4096 Jan 6 11:23 mariadb
drwxr-xr-x 2 dcavalei dcavalei 4096 Jan 6 11:45 nginx
drwxr-xr-x 2 dcavalei dcavalei 4096 Jan 5 15:21 wordpress
basically when i type docker-compose up inside srcs dir, it works as expected, but
if i try:
docker-compose -f ./srcs/docker-compose.yml upwhen i'm at my project root, it does not read my.envfile
I get the following warning:
➜ Inception git:(main) ✗ docker-compose -f ./srcs/docker-compose.yml up
WARNING: The MYSQL_ROOT_PASSWORD variable is not set. Defaulting to a blank string.
WARNING: The MYSQL_USER variable is not set. Defaulting to a blank string.
WARNING: The MYSQL_PASSWORD variable is not set. Defaulting to a blank string.
WARNING: The MYSQL_WP_NAME variable is not set. Defaulting to a blank string.
CodePudding user response:
In some old docker-compose, e.g. docker-compose version 1.24.0, build 0aa59064. The compose will set project-directory as the current folder which run the docker-compose. The behavior changes start v1.28.
So, for you, you have 3 options, you can choose any one.
Upgrade
docker-composetov1.28or latest.Move
.envto the folder which you rundocker-composeUse
--project-directoryto force an alternate working directory, like next:
docker/docker-compose.yaml:
version: "3"
services:
web:
image: "webapp:${TAG}"
docker/.env:
TAG=3
execution:
$ ls
docker
$ docker-compose --project-directory docker -f docker/docker-compose.yaml config
services:
web:
image: webapp:3
version: '3.0'
