0

Django database connection:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'baby',
            'USER': 'root',
            'PASSWORD': 'Thinkonce',
            'HOST': 'host.docker.internal',
            'PORT': '3306',
            'OPTIONS': {
                'charset': 'utf8mb4',
                "init_command": "SET foreign_key_checks = 0;"
            },
        }
    }

docker-compose file

    version: "3"

    services:
    web:
        # network_mode: "host"
        container_name: antiquely
        build: ./
        # command: python manage.py runserver 0.0.0.0:8000
        command: "bash -c 'python manage.py runserver 0.0.0.0:8000'"
        working_dir: /usr/src/antiquely
        ports:
        - "8000:8000"
        volumes:
        - ./:/usr/src/antiquely

    watcher:
        container_name: watcher
        build: ./
        command: "bash -c 'python watcher/app.py'"
        working_dir: /usr/src/antiquely
        volumes:
        - ./:/usr/src/antiquely
        links:
        - web

    celery:
        build: ./
        command: celery -A settings worker -l info
        volumes:
        - ./:/usr/src/antiquely
        links:
        - web
        - redis

    # redis
    redis:
        image: redis
        environment:
        - ALLOW_EMPTY_PASSWORD=yes
        ports:
        - "6379:6379"

Here is my database connection and docker-compose file for django application. I am trying to connect with my locally installed mysql database

watcher | django.db.utils.OperationalError: (2005, "Unknown MySQL server host 'host.docker.internal' (-2)")

I am getting this error

Please have a look how can i fix it ?

  • Are you on a native-Linux host? [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) discusses several approaches to this; have you reviewed that question? – David Maze Jul 10 '21 at 09:52
  • Yes, Native linux host I am able to login mysql also using `mysql -u root -p` – Kiran S youtube channel Jul 10 '21 at 09:54

0 Answers0