I am trying to dockerize my existing django application using docker and docker-compose. Insead of using the default postgres db, I want to create a db with a new name, user id and password.
Here is the config that I am using. When I attach to the db container, I still see only the default account, user and password.
$ cat .env
# Add Environment Variables
DB_NAME=postgres_2
DB_USER=postgres_2
DB_PASS=postgres_2
DB_SERVICE=postgres_2
DB_PORT=5432
$ cat docker-compose.yml
web:
restart: always
build: ./web
expose:
- "8000"
links:
- db:db
- redis:redis
volumes:
- /usr/src/app/static
command: /usr/local/bin/gunicorn django_project.wsgi:application -w 2 -b :8000
nginx:
restart: always
build: ./nginx/
ports:
- "80:80"
volumes:
- /www/static
volumes_from:
- web
links:
- web:web
db:
restart: always
image: postgres:latest
volumes_from:
- data
#env_file: .env
env_file: .env
ports:
- "5432:5432"
redis:
restart: always
image: redis:latest
ports:
- "6379:6379"
data:
restart: always
image: postgres:latest
volumes:
- /var/lib/postgresql
command: "true"
After docker-compose build; docker-compose up -d; docker ps;
When I connect to the db container..
$:/home/django# docker exec -it 41de5b474b88 /bin/bash
root@41de5b474b88:/# su - postgres
No directory, logging in with HOME=/
$ psql postgres_1
psql: FATAL: database "postgres_1" does not exist
$ psql postgres
psql (9.4.4)
Type "help" for help.
postgres=#
Can I configure the new database details from the env file or should I use the approach of a post-installation script as shown in this repo?