Reputation: 626
In my Docker/Laravel 5 project I'm trying to rename .env file of Docker(I have similar file in a Laravel project), so I added 2 lines to docker-compose.yml
:
version: '3.1'
services:
web:
env_file:
./docker_app.env
build:
context: ./web
dockerfile: Dockerfile.yml
environment:
- APACHE_RUN_USER=www-data
volumes:
- ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
ports:
- 8081:80
working_dir: ${APP_PTH_CONTAINER}
db:
image: mysql:5.7.24
restart: always
environment:
MYSQL_ROOT_PASSWORD: 1
volumes:
- ${DB_PATH_HOST}:/var/lib/mysql
but when I'm running the build command I get an error:
$ docker-compose up -d --build
WARNING: The APP_PATH_HOST variable is not set. Defaulting to a blank string.
WARNING: The APP_PTH_CONTAINER variable is not set. Defaulting to a blank string.
WARNING: The DB_PATH_HOST variable is not set. Defaulting to a blank string.
...
Step 2/3 : RUN apt-get update && apt-get install -y libfreetype6-dev libwebp-dev libjpeg62-turbo-dev libpng-dev nano libgmp-dev libldap2-dev netcat sqlite3 git libsqlite3-dev && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && docker-php-ext-install gd pdo pdo_mysql pdo_sqlite zip gmp bcmath pcntl ldap sysvmsg exif && a2enmod rewrite
...
docker_app.env
contents are:
DB_PATH_HOST=./databases
APP_PATH_HOST=./SiteApp
APP_PTH_CONTAINER=/var/www/html/
docker-compose.yml
, docker_app.env
and SiteApp
subdirectory are in the same root directory
If I set an invalid file for env_file
parameter in docker-compose.yml
will I get another error?
How to fix this error?
Thanks!
Upvotes: 0
Views: 3173
Reputation: 12089
The variables in the docker-compose file is not the environment variables in the container, they are env from your working shell (on the host). Docker reads these variables from your host env and substitutes them in the docker-compose file.
You need to export your variables in the docker_app.env.
A quick way to do this is
source docker_app.env
export $(cut -d= -f1 docker_app.env)
(credit to https://unix.stackexchange.com/questions/79064/how-to-export-variables-from-a-file)
PS
You can use docker-compose config
to see substituted result.
Upvotes: 3