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 up
when i'm at my project root, it does not read my .env
file 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.
In some old docker-compose, eg 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-compose
to +v1.28
or latest.
Move .env
to the folder which you run docker-compose
Use --project-directory
to 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'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.