This is my first time using environment variables in docker-compose.
When I run the docker-compose up command I get the error:
docker-compose Couldn't find env file: ${path}\variables.env
Hereinafter "path" is the path to the project in Windows.
Here is my docker-compose.yml:
version: '3.1'
services:
geo:
build:
context: .
image:geo_image
container_name: geo
ports:
- "3003:3003"
volumes:
- ${path}:/var/geo/data
- /app/node_modules
- ${path}:/app
env_file: variables.env
networks:
default:
external:
name: geonw
The variables.env file is located at the root of the project.
Without variables.env everything works fine.
Tell me, please, what is the error?
I tried giving the full path to the file, but that didn't work either.
I also carefully checked the correct name of the file variables.env, there is no error there.
I'm sorry, but it was just my stupid mistake and inattention. I created a variables.env file at a level higher than the directory with the docker-compose.yml file.
2 hours wasted...
Answer: The variables.env and docker-compose.yml files must be in the same directory.
Try this should work.. also try with \ slash .\variables.env
version: '3.1'
services:
geo:
build:
context: .
image:geo_image
container_name: geo
ports:
- "3003:3003"
volumes:
- ${path}:/var/geo/data
- /app/node_modules
- ${path}:/app
env_file:
- ./variables.env
networks:
default:
external:
name: geonw
Related
I have a docker compose file that looks like this
version: '3'
services:
mongodb:
container_name: mongodb
restart: always
image: mongo:4.2.22
networks:
- mynetwork
ports:
- 27017:27017
webapp:
container_name: webapp
image: webapp:1.0
build:
context: .
dockerfile: WebApp
I can run the command docker-compose up -d --build and read/write from the Mongo db. But if I change the DockerFile to be
version: '3'
services:
mongodb:
container_name: mongodb
restart: always
image: mongo:4.2.22
networks:
- mynetwork
ports:
- 27017:27017
webapp:
container_name: webapp
image: webapp:2.0
build:
context: .
dockerfile: WebApp
and run the aforementioned command, the build completes successfully but I do get the error
ERROR: for webapp
Cannot start service webapp: container <container-id> encountered an error during hcsshim::System::CreateProcess:
failure in a Windows system call: The system cannot find the file specified. (0x2)
The code between v1 and v2 is very similar except in v2 I create a couple of new databases. If I switch my docker-compose file to use v1 the containers come up just fine. Curious as to what is causing the error and was wondering if anyone had some suggestions.
docker logs <containerid> does not show anything either.
Thank you
Currently I have setup my service like the following.
version: '3'
services:
gateway:
container_name: gateway
image: node:lts-alpine
working_dir: /
volumes:
- ./package.json:/package.json
- ./tsconfig.json:/tsconfig.json
- ./services/gateway:/services/gateway
- ./packages:/packages
- ./node_modules:/node_modules
env_file: .env
command: yarn run ts-node-dev services/gateway --colors
ports:
- 3000:3000
So I have specified one env_file. But now I want to pass multiple .env files.
Unfortunately, the following is not possible:
env_files:
- .env.secrets
- .env.development
Is there any way to pass multiple .env files to one service in docker-compsoe?
You can specify multiple env files on the env_file option (without s).
For instance:
version: '3'
services:
hello:
image: alpine
entrypoint: ["sh"]
command: ["-c", "env"]
env_file:
- a.env
- b.env
Note that, complementary to #conradkleineespel's answer, if an environment variable is defined in multiple .env files listed under env_file, the value found in the last environment file in the list overwrites all prior (tested in a docker-compose file with version: '3.7'.
I am setting up a new environment with php and mysql in docker. i am using docker-compose file. while installing i realize that i need few more PHP extentensions. I have gone through suggestion online where it is suggested to write a docker file and call it in docker-compose.yml. it is alwasy showing below error
Unsupported config option for services.web: 'dockerfile'
please find docker-compose.yml and Dockerfile below
docker-compose.yml
version: '3'
services:
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: asdf
# MYSQL_DATABASE: test_db
# MYSQL_USER: root
# MYSQL_PASSWORD: asdf
volumes:
- /var/mysql/:/var/lib/mysql
ports:
- "3306:3306"
web:
# image: alankar1985/php7.2:apache2
container_name: php_web
dockerfile: Dockerfile
# command: apt-get install -y php-gd
depends_on:
- db
volumes:
- /var/www/html/:/var/www/html/
ports:
- "80:80"
stdin_open: true
tty: true
Dockerfile
FROM alankar1985/php7.2:apache2
RUN apt install php-gd
Unsupported config option for services.web: 'dockerfile'
The best way to troubleshoot these type of issues is checking the docker-compose reference for the specific version - https://docs.docker.com/compose/compose-file/.
Without testing, the issue is because you need to put dockerfile under build.
Old:
web:
dockerfile: Dockerfile
New:
web:
build:
context: .
dockerfile: Dockerfile
Since you are using the standard Dockerfile filename, you could also use:
build:
context: .
From reference page:
DOCKERFILE Alternate Dockerfile.
Compose uses an alternate file to build with. A build path must also
be specified.
build:
context: .
dockerfile: Dockerfile-alternate
I am trying to learn how to utilize docker-compose and was following instructions until I received an error. Here's my docker-compose file.
version: '3.7'
services:
web:
build: ./app
command: python /usr/src/app/manage.py runserver 0.0.0.0:8000
volumes:
- ./app/:/usr/src/app/
ports:
- 8000:8000
environment:
- SECRET_KEY=my_secret_key
- SQL_ENGINE=django.db.backends.postgresql
- SQL_DATABASE=postgres
- SQL_USER=postgres
- SQL_PASSWORD=postgres
- SQL_HOST=db
- SQL_PORT=5432
depends_on:
- db
db:
images: postgres:10.7-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
volumes:
postgres_data:
When I go back and enter "docker-compose up -d --build", I would get an error saying
ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.db: 'images'
I think I have the indentation correct and 'images' look okay to me.
My docker-compose version is 1.23.2 and trying to run this on Mac.
Any ideas? thanks in advance.
It should be image not images.
So, I have a docker-compose project with this structure:
DockerDev
- docker-compose.yaml
- d-php
- Dockerfile
- scripts-apache
- d-postgresql
- Dockerfile
- scripts
- dev_data_setup.sql
- logs
- pgdata
- www
PHP, Redis, ElasticSearch is OK. But Postgresql doesn't run dev_data_setup.sql, with any diferent solutions to /dockes-entrypoint-initdb.d that I found (volume, ADD, COPY, etc). I tried to run and sh script and nothing.
Could you see this docker-compose and Dockerfile and help me? Thanks
Dockerfile:
FROM postgres:latest
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d
docker-compose.yaml:
version: '2'
services:
php:
build: ./d-php/
hostname: www.domain.com
ports:
- "80:80"
volumes:
- ./www:/var/www/html
- ./d-php/scripts-apache2/apache2.conf:/etc/apache2/apache2.conf
- ./d-php/scripts-apache2/web.conf:/etc/apache2/sites-enabled/web.conf
- ./d-php/scripts-apache2/webservice.conf:/etc/apache2/sites-enabled/webservice.conf
- ./logs:/var/log/apache2
links:
- db
- redis
- elasticsearch
db:
build: ./d-postgresql/
volumes:
- ./pgdata:/pgdata
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- PGDATA=/pgdata
redis:
image: redis:latest
elasticsearch:
image: elasticsearch:2.4.1
So I found the problem.
First: my sql script was trying to recreate postgres user. then, the dockedev_db exited.
Second: I needed to remove all images related to db to docker-compose run the script again.
Thanks for your help.
Your problem is caused by the way you use ADD in your Dockerfile:
FROM postgres:latest
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d
This creates a file called /docker-entrypoint-initdb.d with the content of the dev_data_setup.sql file. What you want is to treat /docker-entrypoint-initdb.d as a directory.
You should change your ADD command to one of the following:
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d/
The trailing slash will treat the dest parameter as a directory. Or use
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d/dev_data_setup.sql
Which will specifically spell out the file name.
Reference: https://docs.docker.com/engine/reference/builder/#/add
If <dest> does not end with a trailing slash, it will be considered a regular file and the contents of <src> will be written at <dest>.