I have used cookiecutter-django
for my django projects. I am using docker to run the project locally. The project is running well. However, i could not explore postgres while using docker.
Here are the steps i followed to run the project
docker-compose -f local.yml build
docker-compose -f local.yml up -d
docker-compose run django python manage.py makemigrations
docker-compose run django python manage.py migrate
local.yml looks like following
version: '3'
volumes:
local_postgres_data: {}
local_postgres_data_backups: {}
services:
django: &django
build:
context: .
dockerfile: ./compose/local/django/Dockerfile
image: travel_local_django
depends_on:
- postgres
- mailhog
volumes:
- .:/app
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
ports:
- "8000:8000"
command: /start
postgres:
build:
context: .
dockerfile: ./compose/production/postgres/Dockerfile
image: travel_production_postgres
volumes:
- local_postgres_data:/var/lib/postgresql/data
- local_postgres_data_backups:/backups
env_file:
- ./.envs/.local/.postgres
compose/production/postgres/Dockerfile
FROM postgres:11.3
COPY ./compose/production/postgres/maintenance /usr/local/bin/maintenance
RUN chmod +x /usr/local/bin/maintenance/*
RUN mv /usr/local/bin/maintenance/* /usr/local/bin \
&& rmdir /usr/local/bin/maintenance
.envs/.local/.postgres
# PostgreSQL
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=simplifytour
POSTGRES_USER=debug
POSTGRES_PASSWORD=debug
when i did docker-compose -f local.yml ps
, i get the container related to this project. I then executed the postgres container with command docker exec -it travel_postgres_1 sh
. There i tried running the command like psql
, psql -U postgres
but nothing worked for me. I wanted to explore the postgres like listing the tables, connecting to the database etc.
Did i miss any steps? How can i use postgres container?