Skip to content

cusnsoftware/postgresql-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PostgreSQL Docker Setup

This repository contains a docker-compose.yml configuration to run a PostgreSQL 16 container with persistent data and a custom network.

🐘 Services

  • 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

πŸ“ Project Structure

.
β”œβ”€β”€ docker-compose.yml
└── README.md

πŸš€ How to Run

  1. Make sure Docker is installed and running.
  2. Run the following command in the project root:
docker-compose up -d

This will start the PostgreSQL container in detached mode.

πŸ“¦ Volumes

  • pgdata: Persists the PostgreSQL data across container restarts.

🌐 Network

  • mynetwork: A custom bridge network for connecting multiple services easily.

πŸ›‘ Stopping the Container

docker-compose down

Add -v if you want to remove volumes as well:

docker-compose down -v

πŸ”Œ Connecting to the Database

You can connect to the database using any PostgreSQL client with these credentials:

  • Host: localhost
  • Port: 5432
  • Database: server_db
  • Username: iam
  • Password: password

Example connection string:

postgresql://iam:password@localhost:5432/server_db

Using psql command line:

psql -h localhost -p 5432 -U iam -d server_db

πŸ“Œ Notes

  • The credentials and database name are defined in the environment section. 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.

βœ… Ready to integrate with your backend or other services!

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

postgresql-docker

About

Create PostgreSQL Docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published