2

Official site says, that if you wanna build postgresql databse just put varibles POSTGRES_USER, POSTGRES_PASSWORD and POSTGRES_DB. I put them into .env file and write in docker-compose file env_file: ./.env, but then django says: django.db.utils.OperationalError: FATAL: database "languages" does not exist. It means I should write .sql script with commands. Questions:

  1. Writing .sql sript is the only way to make it work?
  2. How can I write it and where to put it if I don't want explicitly write sensetive info like password, I wanna use .env file as i will store .sql script in public repo?

My .env file

DEBUG=True
SECRET_KEY=...
POSTGRESQL_DATABASE=languages
POSTGRESQL_USERNAME=admin
POSTGRESQL_PASSWORD=pass
POSTGRESQL_ADDRESS=postgres
POSTGRES_DB=languages

My docker-compose file:

version: '3'

services:
  web:
    build: ./web 
    env_file: ./web/microservice/.env
    volumes:
      - ./web:/code/
    depends_on:
      - postgres
    command: python manage.py runserver 0.0.0.0:8000

  nginx:
    build: ./nginx/
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./web/static:/code/static
    depends_on:
      - web

  postgres:
    image: postgres:latest
    ports:
      - "5432:5432"
    env_file: ./web/microservice/.env
    volumes:
      - /var/lib/postgresql/data/

My Dockefile:

FROM python:3.5
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD ./requirements.txt /code/
RUN pip install --no-cache-dir -r requirements.txt
ADD . /code/
EXPOSE 8000
CMD ["/usr/local/bin/gunicorn", "translation_microservice.wsgi", "-w", "2", "-b", ":8000", "--access-logfile", "-", "--capture-output"]

1 Answer 1

2

Seems like you are using incorrect variable names. Change POSTGRESQL_USERNAME to POSTGRES_USER and so on in your .env file

You might have to clear the docker volume containing your database if it has already been built using another environment. The default is to create a user and a database named postgres

Do not add the .env file to a public repo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.