Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. create a new folder: database_postgres

  2. create a new text file inside the folder called: docker-compose.yml

  3. add this code snipped into the file …

Code Block
languageyaml
version: '3'

services:
  postgres:
    image: postgres:14.4
    restart: always
    ports:
      - 5432:5432
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password
    volumes:
      - ./postgres-data:/var/lib/postgresql/data

...

Code Block
docker-compose up -d

...


  1. This example script will create Docker Compose for Postgres & pgAdmin

...

  1. Please make sure to update marked: {CHANGE HERE}

Code Block
languageyaml
version: '3.5'

services:
  postgres:
    container_name: postgres_container
    image: postgres
    environment:
      POSTGRES_USER: {CHANGE HERE}
      POSTGRES_PASSWORD: {CHANGE HERE}
      PGDATA: /data/postgres
    volumes:
       - postgres:/data/postgres
    ports:
      - "5432:5432"
    networks:
      - postgres
    restart: unless-stopped
 
  pgadmin:
    container_name: pgadmin_container
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: {CHANGE HERE}
      PGADMIN_DEFAULT_PASSWORD: {CHANGE HERE}
      PGADMIN_CONFIG_SERVER_MODE: 'False'
    volumes:
       - pgadmin:/root/.pgadmin
    ports:
      - "6060:80"
    networks:
      - postgres
    restart: unless-stopped

networks:
  postgres:
    driver: bridge

volumes:
    postgres:
    pgadmin:


Run this command to start the database:

Code Block
docker-compose up -d

After installation you can access pgAdmin via port 6060 to manage the database.
In a web browser navigate to: http://my-server:6060

Configure Postgres Server

...