Postgres + PGAdmin Docker Compose

You can run Postgres and PGAdmin with a single docker-compose command

docker-compose -f ~/path-to-your-directory/docker-compose.yml up --build -d;

Contents of the docker-compose.yml file as follows:

With this file you can pass environment variables or YML file will pick the defaults for you.

 version: '3.5'

services:
  postgresdb:
    container_name: postgres_container
    image: postgres
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-postgres}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
      PGDATA: /data/postgres
    volumes:
       - ../../databases/postgresdb:/data/postgres
    ports:
      - "5432:5432"
    networks:
      - postgres
    restart: unless-stopped
  
  pgadmin:
    container_name: pgadmin_container
    image: dpage/pgadmin4:4
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
      PGADMIN_LISTEN_ADDRESS: ${PGADMIN_LISTEN_ADDRESS:-0.0.0.0}
      PGADMIN_CONFIG_CONSOLE_LOG_LEVEL: ${PGADMIN_CONFIG_CONSOLE_LOG_LEVEL:-10}
    volumes:
        #If you want to place your database outside uncomment following line and comment the next one.
        # - ../../databases/pgadmin_volume:/var/lib/pgadmin
        - pgadmin_volume:/var/lib/pgadmin
    ports:
      - "${PGADMIN_PORT:-5050}:80"
    networks:
      - postgres
    restart: unless-stopped
    depends_on:
      - postgresdb

networks:
  postgres:
    driver: bridge

volumes:
    pgadmin_volume:

Enjoy!

Credits:

My Github fork (ipv6 disabled): https://github.com/mustafabugra/compose-postgres

Original Repo: https://github.com/khezen/compose-postgres

Bu yazı bugün 1 kere olmak üzere toplam 1 kere okundu.

Posted in: Development

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Adult Webcam xXx