[Fixed]-Docker-compose v2 expose port to machine

1👍

Try to use dockers internal network features to let the container talk to each other.

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

and in your django.conf

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

I don’t know on what es depends bu i hope you get the Point

FYI depends_on reference

👤Ohmen

Leave a comment