Below is a sample docker-compose.yml file for running the Users Microservice with PostgreSQL 16 (does not matter for psql 16 when running locally). To get started, make sure you have both Docker and docker-compose installed on your system. Then, place this file in your project’s root directory and run the containers as shown in the steps below.
version: '3'
services:
users_db:
image: postgres:16
volumes:
- pg_data:/var/lib/postgresql/data
ports:
- 5433:5432
environment:
POSTGRES_DB: "users_db"
POSTGRES_USER: "users_db"
POSTGRES_PASSWORD: "users_db"
users_main:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/users_main
ports:
- "8001:8000"
depends_on:
- users_db
volumes:
pg_data:
How to Run
- Install Docker and docker-compose Make sure you have Docker and docker-compose installed.
- Place the File
Save the YAML content to your project’s root directory as
docker-compose.yml. - Build and Start the Containers
In your terminal or command prompt, navigate to the folder containing
docker-compose.ymland run:docker-compose up --buildThis command will build the images (if needed) and start the containers. - Access the Application
- Users Database: exposed on port
5433 - Users Microservice: available on port
8001of your local machine.
- Users Database: exposed on port
Once everything is running, you can verify the setup by visiting http://localhost:8001/ in your browser.
Make sure to set the required environment variables before starting, or you may encounter an error. For more information, see: http://localhost:3000/users/getting_started/environment_variables