django.db.utils 2006,“无法连接到本地MySQL \ /var/run/mysqld/mysqld.sock \”

时间:2019-06-28 13:15:24

标签: django docker

尝试docker-compose并永久陷入SQL套接字问题。

这是我的docker-compose.yml

version: '3'

services:
web:
    build: .
    command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
    container_name: jl_backend
    volumes:
    - .:/jl_backend
    ports:
    - "8000:8000"
    depends_on:
        - db
db:
    image: mysql:latest
    command: mysqld --default-authentication-plugin=mysql_native_password
    volumes:
    - "./mysql:/var/lib/mysql"
    ports:
    - "3307:3307"
    # changed the port from 3306 so that it doesnt bump into SQL
    restart: always
    environment:

这是错误:

jl_backend |     return Connection(*args, **kwargs)
jl_backend |   File "/usr/local/lib/python3.6/site-packages/MySQLdb/connections.py", line 208, in __init__
jl_backend |     super(Connection, self).__init__(*args, **kwargs2)
jl_backend | django.db.utils.OperationalError: (2006, 'Can\'t connect to local MySQL server through socket \'/var/run/mysqld/mysqld.sock\' (2 "No such file or directory")')
jl_backend exited with code 1

0 个答案:

没有答案