Docker-compose v2将端口暴露给机器

我曾经使用docker-compose的v1来运行一组服务,然后使用Django的dev服务来连接它们。 我曾经使用<machine_ip>:<port>连接到服务(如db)(对于postgres来说,smt就像192.168.99.100:5432一样)

现在,我刚刚安装了Docker for Mac,v1不能正常工作。 我搬到版本2,但Django抱怨没有服务监听端口5432 。 据我了解这是一个network的问题,但我不能得到我的头在如何configuration它。 从理论上讲,组合中的所有服务都会创build一个默认networking,一般情况下都不错,但对我来说不是这样。 我使用组合来启动一组服务来连接到我本地的django执行。

这是我的docker-compose文件

 version: '2' services: db: image: postgres:9.4 volumes_from: - data ports: - "5432:5432" es: image: elasticsearch:2.3 ports: - "9200:9200" - "9300:9300" rabbit: image: rabbitmq:3 ports: - "5672:5672" - "48429:48429" data: # use this that is already downloaded # links just to keep the db image: alpine:3.3 command: echo 'Data Container for PostgreSQL' volumes: - /var/lib/postgresql/data networks: default: driver: bridge 

在我的django conf

 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'postgres', 'USER': 'postgres', 'HOST': '192.168.99.100', # 'localhost', 'PORT': '5432' # '6543' }, } 

其中192.168.99.100docker-machine ip

结果是

 django.db.utils.OperationalError: could not connect to server: Connection refused Is the server running on host "192.168.99.100" and accepting TCP/IP connections on port 5432? 

任何帮助,我可以如何公开所有这些端口到机器IP?

尝试使用docker内部networkingfunction让容器相互交谈。

 version: '2' services: db: image: postgres:9.4 volumes: - datavolume_postgres:/var/lib/postgresql/data ports: - "5432:5432" es: image: elasticsearch:2.3 ports: - "9200:9200" - "9300:9300" rabbit: image: rabbitmq:3 ports: - "5672:5672" - "48429:48429" depends_on: - "db" # Named volume volumes: datavolume_postgres: {} #You dont need to specify the default network 

并在你的django.conf

 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'postgres', 'USER': 'postgres', 'HOST': 'db', # 'localhost', 'PORT': '5432' # '6543' }, } 

我不知道什么取决于我不希望你得到点

供参考依赖