This repository contains a docker-compose.yml configuration to run a PostgreSQL 16 container with persistent data and a custom network.
- PostgreSQL (
server-db)- Image: postgres:16
- Container name: server-db
- Port: 5432
- Environment:
- POSTGRES_USER=iam
- POSTGRES_PASSWORD=password
- POSTGRES_DB=server_db
- Volume: pgdata (for persistent data)
- Network: mynetwork
.
βββ docker-compose.yml
βββ README.md
- Make sure Docker is installed and running.
- Run the following command in the project root:
docker-compose up -dThis will start the PostgreSQL container in detached mode.
- pgdata: Persists the PostgreSQL data across container restarts.
- mynetwork: A custom bridge network for connecting multiple services easily.
docker-compose downAdd -v if you want to remove volumes as well:
docker-compose down -vYou can connect to the database using any PostgreSQL client with these credentials:
- Host: localhost
- Port: 5432
- Database: server_db
- Username: iam
- Password: password
postgresql://iam:password@localhost:5432/server_db
psql -h localhost -p 5432 -U iam -d server_db- The credentials and database name are defined in the
environmentsection. You may update them as needed. - The PostgreSQL data will persist across container restarts thanks to the named volume.
- The custom network makes it easy to connect other services to this database.
For production use, consider:
- Using environment variables or secrets for sensitive data
- Setting up proper backup strategies
- Configuring appropriate resource limits
- Using more secure passwords