I’m working with docker version 1.12.0-rc2 and docker-compose version 1.8.0-rc1 on a Windows 10 environment.
I want to use a postgres container with a custom database and password.
When I use the following Dockerfile the container works as expected, with the specified database:
FROM postgres:9.5
ENV POSTGRES_DB mydatabase
ENV POSTGRES_PASSWORD mypassword
The container is build and started with
docker build . -t progres
docker run -d -p 5432:5432 -v ./data:/var/lib/postgresql/data postgres
When I try to do the same with docker-compose, and the following yaml file, the database is not created:
version: '2'
services:
db:
image: postgres
build: .
ports:
- "5432:5432"
volumes:
- ./data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=mydatabase
- POSTGRES_PASSWORD=mypassword
Starten with command docker-compose up -d
Environment variables in the container show in both cases the given variables in the files.