Skip to content

How to access the pgsql database in the docker container? #9212

Answered by tecoholic
mitian233 asked this question in Q&A
Discussion options

You must be logged in to vote

There are 2 ways to do it.

  1. Add a ports mapping to the Postgres service on docker-compose.yml and open the port to the host and connect from the host
  2. Add PgAdmin to the docker-compose.yml and link it to the postgres container.

For option one you would do something like the following and and connect to it from pgadmin using "localhost:5432"

  db:
    restart: always
    image: postgres:12.2-alpine
    networks:
      - internal_network
+    - external_network
+  ports:
+    - "5432:5432" 
    env_file:
      - .config/docker.env
    volumes:
      - ./db:/var/lib/postgresql/data

For option 2, you will have to add a new section like

  pdadmin:
    image: dpage/pgadmin4
    networks:
      - 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mitian233
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants