• <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

        django.db.utils.OperationalError: (2002, quot;Can#39;t connect to MySQL server on #39;db#39; (115)quot;)(django.db.utils.OperationalError: (2002, Cant connect to MySQL server on db (115)))
          <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)")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)
                  <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>
                    <tbody id='QkfWP'></tbody>

                      <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>