This repository contains a Docker Compose configuration to launch a PostgreSQL database and a pgAdmin instance for database management.
Ensure the following are installed on your system:
Clone this repository to your local machine:
git clone https://github.com/sk-at-redgate/pgsql-docker-demo.git
cd pgsql-docker-demoIn the root directory of the repository, execute the following commands to create necessary directories and set permissions:
# Create required directories
mkdir -v {data,pgadmin-data,secrets,temp,uploads}
mkdir -v pgadmin-data/{azurecredentialcache,sessions,storage}
# Set ownership for pgAdmin data directory
chown -vR 5050:5050 pgadmin-data/ uploads/
# Set ownership for PostgreSQL data directory
chown -Rv 1001:1001 data/ temp/ Create the following secret files in the secrets directory as referenced in the docker-compose.yaml file:
-
Database User Secret
- Path:
secrets/db_user.txt - Content: Add the database user name here.
- Path:
-
Database Password Secret
- Path:
secrets/db_password.txt - Content: Add the database password here.
- Path:
-
pgAdmin Password Secret
- Path:
secrets/pgadmin_passwd.txt - Content: Add the default password for pgAdmin here.
- Path:
Run the following command in the root directory of the repository:
docker-compose up -dRun the following command:
docker-compose down- Image: Official PostgreSQL image.
- Ports: Host
5555→ Container5432. - Data Directory:
data/(local) →/var/lib/postgresql/data(container). - Temporary Directory:
temp/(local) →/tmp/(container). - Secrets:
db-user-secret: User credentials.db-password-secret: Password credentials.
- Network: Custom network with IP
175.20.0.6.
- Image: Official pgAdmin image.
- Ports: Host
9999→ Container80. - Data Directory:
pgadmin-data/(local) →/var/lib/pgadmin(container). - Secrets:
pgadmin_pwd_secret: Default password.
- Network: Custom network with IP
175.20.0.2.
Both services include health checks to ensure proper functioning:
- PostgreSQL: Uses
pg_isready. - pgAdmin: Uses an HTTP ping to
http://localhost:80/misc/ping.
A custom Docker network (db_demo_net) is used with the following subnet:
subnet: '175.20.0.0/24'For more details, refer to the docker-compose.yaml file.
For more details, refer to the docker-compose.yaml.documentation file.