In order to pull the container and run it using docker compose up
you first need to add it to your docker-compose.yml
. The backend relies on the PostgreSQL server as well, so make sure to add it as well like this:
version: '3.8'
# Setting up the PostgreSQL DB Container services
services:
db:
image: 'postgres:latest'
restart: always
env_file: # The location we use to store all of our secrets
- .env
volumes:
- ./db-data/:/var/lib/postgresql/data/
ports:
- 5432:5432
server:
image: 'docker.pkg.github.com/umass-rescue/596-s22-backend/backend:latest'
depends_on:
- db
volumes:
- ./be-data/:/backend/
command: uvicorn app.main:app --host 0.0.0.0 --port 8000
env_file:
- .env
ports:
- 8000:8000
Running this โas isโ will immediately fail with the error .env file is missing
. That is because we need to manually add the .env
file ourselves. This is where we store all of our container secrets. By default, this file is added to our .gitignore
because we do not want to store secrets in Github ever.
In order to resolve this error, first create the file .env
and then paste this into the file:
# PostgreSQL Container Secrets
POSTGRES_USER=username
POSTGRES_PASSWORD=password
POSTGRES_DB=default_database
Resolving this error will now allow the backend to run, however, trying to get or push any data from the database will result in error, this is because we still need to setup our newly created database.
Our database is managed using Alembic, a powerful database migration service that helps manage upgrades to our database over time. In order to bring our database up to speed, we need to run a couple of commands:
First, lets log into the command interface of our database, go to docker desktop and click on the CLI button:
Second, in the command line interface, type this command and hit enter: