Docker Compose + Postgres: Expose port

随声附和 提交于 2020-01-02 06:18:56

问题


I am currently trying to use Docker for my new Django/Postgres project. I am working on a Mac and usually use Postico to quickly connect to my database.

I used to connect like here:

I used the official Docker documentation to setup docker-compose. I now have the issue, that I can't connect via Postico to the postgres db. It seems to me that the problem comes from the ports not being exposed.

version: '3'

services:
  db:
    image: postgres
  web:
    build: .
    command: python3 manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

回答1:


Just map the port to the host machine, add this to the db service in your Compose file:

ports:
  - "5432:5432"

Also make sure to set the postgres password variable in the compose file like this

environment:
  POSTGRES_PASSWORD: example

The default user is postgres, you can change it with the POSTGRES_USER variable.

You can read about the usage of the image with all options here: https://hub.docker.com/_/postgres/



来源:https://stackoverflow.com/questions/52567272/docker-compose-postgres-expose-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!