Skip to content

Instantly share code, notes, and snippets.

@davidostermann
Last active November 1, 2024 12:49
Show Gist options
  • Save davidostermann/0190da1e1544dfd1625e53ca8a74e258 to your computer and use it in GitHub Desktop.
Save davidostermann/0190da1e1544dfd1625e53ca8a74e258 to your computer and use it in GitHub Desktop.
Docker compose Postgres Adminer
version: '3.1'
services :
db:
image: postgres:10-alpine
ports:
- "5432:5432"
environment:
POSTGRES_USER: user1
POSTGRES_PASSWORD: changeme
POSTGRES_DB: tododb
admin:
image: adminer
restart: always
depends_on:
- db
ports:
- 8080:8080
@adxl
Copy link

adxl commented Jul 12, 2021

Thank you ! :)

@mlarizzate
Copy link

Thank you!
I'll implement this in an SQL course over Pay With Docker platform to provide environment for the students.

@nemanjam
Copy link

Your example is with postgres and adminer in same docker-compose.yml. How should I set adminer hostname and networks if I want to use adminer on other postgres container on same server?

docker-compose.yml for reverse proxy in which I want to add Adminer

services:
  traefik:
    image: "traefik:v2.5.6"
    networks:
      - proxy
  ...

  adminer:
    image: adminer:4.8.1-standalone
    networks:
      - proxy
    labels:
      - "traefik.http.routers.adminer.rule=Host(`adminer.${DOMAIN}`)"
      - "traefik.http.services.adminer.loadbalancer.server.port=8080"

networks:
  proxy:
    external: true

docker-compose.yml for my app, Adminer should connect to this Postgres container

 app:
    depends_on:
      - postgres-db-prod
  ...
    networks:
      - proxy
      - internal

  postgres-db-prod:
    image: postgres:14-alpine
    container_name: postgres-db-prod
    restart: unless-stopped
    ports:
      - 5432:5432
    volumes:
      - ./prisma/pg-data:/var/lib/postgresql/data
    env_file:
      - .env.local
    labels:
      - 'traefik.enable=false'
    networks:
      - proxy
      - internal

networks:
  proxy:
    external: true
  internal:
    external: false

@davidostermann
Copy link
Author

@nemanjam This example was originally made only for local use.

@Asterlc
Copy link

Asterlc commented Nov 20, 2022

Thank you so much !

@DavidSolus
Copy link

DavidSolus commented Dec 30, 2022

When I try and log into the database I run into this issue, not sure what's causing it

Unable to connect to PostgreSQL server: could not connect to server: Connection refused Is the server running on host "localhost"
(127.0.0.1) and accepting TCP/IP connections on port 5432? could not connect to server: Cannot assign requested address Is the server
running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?

I figured out the issue was that I was trying to connect to the wrong server name. I used the name of the container and it worked.

@hericah
Copy link

hericah commented Jun 26, 2023

Thanks!

@danLeBrown
Copy link

@DavidSolus, thanks 👍

@kusa-mochi
Copy link

@DavidSolus thanks! It helped me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment