• <i id='PRiRJ'><tr id='PRiRJ'><dt id='PRiRJ'><q id='PRiRJ'><span id='PRiRJ'><b id='PRiRJ'><form id='PRiRJ'><ins id='PRiRJ'></ins><ul id='PRiRJ'></ul><sub id='PRiRJ'></sub></form><legend id='PRiRJ'></legend><bdo id='PRiRJ'><pre id='PRiRJ'><center id='PRiRJ'></center></pre></bdo></b><th id='PRiRJ'></th></span></q></dt></tr></i><div id='PRiRJ'><tfoot id='PRiRJ'></tfoot><dl id='PRiRJ'><fieldset id='PRiRJ'></fieldset></dl></div>
    1. <legend id='PRiRJ'><style id='PRiRJ'><dir id='PRiRJ'><q id='PRiRJ'></q></dir></style></legend>

      <small id='PRiRJ'></small><noframes id='PRiRJ'>

        • <bdo id='PRiRJ'></bdo><ul id='PRiRJ'></ul>
        <tfoot id='PRiRJ'></tfoot>

        django.db.utils.OperationalError: (2002, "Can't con

        时间:2023-07-06
          <bdo id='vF6ji'></bdo><ul id='vF6ji'></ul>
            <tbody id='vF6ji'></tbody>
                <legend id='vF6ji'><style id='vF6ji'><dir id='vF6ji'><q id='vF6ji'></q></dir></style></legend>
                <i id='vF6ji'><tr id='vF6ji'><dt id='vF6ji'><q id='vF6ji'><span id='vF6ji'><b id='vF6ji'><form id='vF6ji'><ins id='vF6ji'></ins><ul id='vF6ji'></ul><sub id='vF6ji'></sub></form><legend id='vF6ji'></legend><bdo id='vF6ji'><pre id='vF6ji'><center id='vF6ji'></center></pre></bdo></b><th id='vF6ji'></th></span></q></dt></tr></i><div id='vF6ji'><tfoot id='vF6ji'></tfoot><dl id='vF6ji'><fieldset id='vF6ji'></fieldset></dl></div>

                <tfoot id='vF6ji'></tfoot>

                <small id='vF6ji'></small><noframes id='vF6ji'>

                1. 本文介绍了django.db.utils.OperationalError: (2002, "Can't connect to MySQL server on 'db' (115)")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  This has already been asked, but none of the answers have helped me. This is my configuration. Im running docker-compose with two services, a web app in django and the database in mariadb. I can connect normally to my local db with this exact configuration, only changing the host in settings.py to localhost. When i run docker-compose up, the web service stops immediately after trying to connect to the database, and return this error.

                  django.db.utils.OperationalError: (2002, "Can't connect to MySQL server on 'db' (115)")

                  Dockerfile

                  FROM python:3.7
                  
                  RUN mkdir /app
                  
                  COPY requierments.txt /app/
                  
                  WORKDIR /app
                  
                  RUN pip install -r requierments.txt
                  
                  COPY . /app/
                  

                  docker-compose.yml

                  version: '3'
                  
                  services:
                    db:
                      image: mariadb:10.2
                      expose:
                        - 3306
                      ports:
                        - "3306:3306"
                      environment:
                        MYSQL_DATABASE: 'django_backend'
                        MYSQL_USER: 'django'
                        MYSQL_PORT: '3306'
                        MYSQL_PASSWORD: 'mysql1234pass'
                        MYSQL_ROOT_PASSWORD: 'password'
                  
                    web:
                      build: .
                      image: backendblockchain_web
                      volumes:
                        - .:/app
                      ports:
                        - "8000:8000"
                      depends_on:
                        - db
                      links:
                        - db
                      command:
                        - /bin/bash
                        - -c
                        - |
                          sleep 10
                          python3 manage.py migrate
                          python3 manage.py runserver 0.0.0.0:8000
                  

                  setting.py

                  DATABASES = {
                      'default': {
                          'ENGINE': 'django.db.backends.mysql',
                          'NAME': 'django_backend',
                          'USER': 'django',
                          'PASSWORD': 'mysql1234pass',
                          'HOST': 'db',
                          'PORT': '3306'
                      }
                  }
                  

                  解决方案

                  your WEB containers starts before the DB is up and running , you need to wait for it using one of these methods or starting your DB first manually with docker-compose up db

                  这篇关于django.db.utils.OperationalError: (2002, "Can't connect to MySQL server on 'db' (115)")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python MariaDB pip 安装失败,缺少 mariadb_config 下一篇:使用 to_sql 和 sqlalchemy 到 mariadb 数据库的 pandas 数据框

                  相关文章

                  <i id='QkfWP'><tr id='QkfWP'><dt id='QkfWP'><q id='QkfWP'><span id='QkfWP'><b id='QkfWP'><form id='QkfWP'><ins id='QkfWP'></ins><ul id='QkfWP'></ul><sub id='QkfWP'></sub></form><legend id='QkfWP'></legend><bdo id='QkfWP'><pre id='QkfWP'><center id='QkfWP'></center></pre></bdo></b><th id='QkfWP'></th></span></q></dt></tr></i><div id='QkfWP'><tfoot id='QkfWP'></tfoot><dl id='QkfWP'><fieldset id='QkfWP'></fieldset></dl></div>
                  <tfoot id='QkfWP'></tfoot>

                    <legend id='QkfWP'><style id='QkfWP'><dir id='QkfWP'><q id='QkfWP'></q></dir></style></legend>
                  1. <small id='QkfWP'></small><noframes id='QkfWP'>

                      <bdo id='QkfWP'></bdo><ul id='QkfWP'></ul>