0

Hi everyone i was working in a django project with docker. and i have a problem to connect docker container with postgres database, one the the way to connect is network_mode: host but i want to connect using custom network.

version: '3.3'

services:
  web:

    restart: always

    container_name: main
    command:
      - /bin/bash
      - -c
      - |
        python manage.py makemigrations  accounts
        python manage.py migrate
        python manage.py runserver
    image: main
    build: .
    volumes:
      - .:/main
    ports:
      - "8000:8000"
    extra_hosts:
      - "dbhost:172.17.0.1"
    networks:
      - backend
networks:
  backend:
volumes:
  static:
David Maze
  • 130,717
  • 29
  • 175
  • 215

1 Answers1

0

If you are on Docker Desktop with WSL2 you can use host.docker.internal other than that you need to get the Gateway Ip from here: docker network inspect bridge it might be 172.17.0.1. Also to do this you don't want to use a specific network in your compose file but use the default one.

zsolt
  • 1,233
  • 8
  • 18