I would like to create postgresql database in docker with my Django project. I'm trying to do it using init.sql file but it doesn't work:
settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'aso',
'USER': 'postgres',
'HOST': 'db',
'PORT': 5432,
}
}
init.sql:
CREATE USER postgres;
CREATE DATABASE aso;
GRANT ALL PRIVILEGES ON DATABASE aso TO postgres;
My updated Dockerfile:
FROM python:3.6.1
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip3 install -r requirements.txt
ADD . /code/
FROM library/postgres
ADD init.sql /docker-entrypoint-initdb.d/
Unfortunately I get:
db_1 | LOG: database system was shut down at 2017-07-05 14:02:41 UTC
web_1 | /usr/local/bin/docker-entrypoint.sh: line 145: exec: python3: not found
db_1 | LOG: MultiXact member wraparound protections are now enabled
db_1 | LOG: autovacuum launcher started
db_1 | LOG: database system is ready to accept connections
dockerpri_web_1 exited with code 127
I was trying with this Dockerfile, too:
FROM python:3.6.1
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip3 install -r requirements.txt
ADD . /code/
FROM library/postgres
ENV POSTGRES_USER docker
ENV POSTGRES_PASSWORD docker
ENV POSTGRES_DB aso
My docker-compose.yml:
version: '3'
services:
db:
image: postgres
web:
build: .
command: python3 PROJECT/backend/project/manage.py runserver 0.0.0.0:8001
volumes:
- .:/code
ports:
- "8001:8001"
depends_on:
- db
Dockerfileworks with regards to multipleFROMinstructions. Can you also post yourdocker-compose.yml? What you are currently doing isn't possible but I can offer a suggestion.