Formulir Kontak

Nama

Email *

Pesan *

Cari Blog Ini

Docker Compose For Postgresql And Pgadmin

Docker Compose for PostgreSQL and pgAdmin

Overview

In this article, we'll create a Docker Compose script for PostgreSQL and pgAdmin, making it easy to manage PostgreSQL in a containerized environment.

Creating the Docker Compose Configuration

1. Create a file named `docker-compose.yml`. 2. Paste the following content into the file: ``` version: '3.8' services: postgres: image: postgres:latest volumes: - pgdata:/var/lib/postgresql/data ports: - "5432:5432" environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DB} pgadmin: image: dpage/pgadmin4 ports: - "8080:80" volumes: - pgadmin-data:/var/lib/pgadmin environment: PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL} PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD} volumes: pgdata: {} pgadmin-data: {} ``` 3. Replace the placeholders with your desired values for: - `POSTGRES_USER` - `POSTGRES_PASSWORD` - `POSTGRES_DB` - `PGADMIN_DEFAULT_EMAIL` - `PGADMIN_DEFAULT_PASSWORD`

Building and Starting the Containers

1. Run the following command to build and start the containers: ``` docker-compose up -d ``` 2. Wait for the containers to finish building and starting.

Quick Access to pgAdmin

1. Open your browser and navigate to `http://localhost:8080`. 2. You should now have access to the pgAdmin interface.

Conclusion

By using Docker Compose, we can easily set up and manage PostgreSQL and pgAdmin containers. This allows us to quickly create and interact with PostgreSQL databases in a flexible and isolated environment.


Komentar