Docker Compose - Postgres
services:
# Backend API
smart-brain-api:
container_name: backend
build: ./
command: npm start
working_dir: /usr/src/smart-brain-api
environment:
POSTGRES_USER: dockerbot
POSTGRES_PASSWORD: secret
POSTGRES_DB: smart-brain-docker
POSTGRES_HOST: postgres
links:
- postgres
ports:
- "3000:3000"
volumes:
- ./:/usr/src/smart-brain-api
# Postgres
postgres:
environment:
POSTGRES_USER: dockerbot
POSTGRES_PASSWORD: secret
POSTGRES_DB: smart-brain-docker
POSTGRES_HOST: postgres
build: ./postgres
ports:
- "1234:5432"enEnvironment is the process.env to create and connect database in docker environment. POSTGRES_HOST has to be the same name with the service name. (POSTGRES_URI is not working)
Links is to connect the API with other services like postgres and redis
Build is to build from Dockerfile in the ./postgres folder (the opposite of image: postgres <= building from image from DockerHub)
Ports is to establish port connection (use other than 5432 if it is being used)
From is to download the postgres version.
Get the sql file from /tables/ folder and map it to the container folder, /docker-entrypoint-initdb.d/tables/ (We will do the same later for the seed data)
Run deploy_schemas.sql into the main container folder
Last updated
Was this helpful?