skip to Main Content

I’m trying to connect to an express database on sql server accesible throughout 192.168.0.130:1433 on local network from Docker Django container.

I’m on a Mac and from local host i have ping

$ ping 192.168.0.130
64 bytes from 192.168.0.130: icmp_seq=0 ttl=128 time=5.796 ms
64 bytes from 192.168.0.130: icmp_seq=1 ttl=128 time=2.234 ms

But inside docker container get timeout error.

docker-compose.yml:

version: '3.7'
services:
  ...
  django:
    container_name: djangonoguero_django_ctnr
    build:
      context: .
      dockerfile: Dockerfile-django
    restart: unless-stopped
    env_file: ./project/project/settings/.env
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - ./project:/djangonoguero
    depends_on:
     - postgres
    ports:
      - 8000:8000
    networks:
      - djangonoguero-ntwk

networks:
  djangonoguero-ntwk:
    driver: bridge

Anybody could help me please ?
Thanks in advance.

2

Answers


  1. Chosen as BEST ANSWER

    Reset fabric default values from Docker solved the problem.


  2. For example, you have postgres container:

    db:
      image: postgres
      environment:
        # This is for example, not use this in production!!!
        POSTGRES_USER: developer
        POSTGRES_DB: db
        POSTGRES_PASSWORD: Passw0rd33
    ...
    

    Then, in your django project settings, you should write:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': 'db',
            'USER': 'developer',
            'PASSWORD': 'Passw0rd33',
            'HOST': 'db',
        }
    }
    

    Be careful, this is example settings! Best practice is to store this data in .env file!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search