[英]docker compose up generate (2005, "Unknown MySQL server host 'db' (-2)") error
Hi all i'm trying to dockerize a django application with a connexion to the database.大家好,我正在尝试使用与数据库的连接来 dockerize 一个 django 应用程序。 when i run docker compose up i get this error when the dockerfile is making migrations
django.db.utils.OperationalError: (2005, "Unknown MySQL server host 'db' (-2)") ERROR: Service 'web' failed to build: The command '/bin/sh -c python manage.py makemigrations' returned a non-zero code: 1
当我运行 docker compose up 时,当 dockerfile 进行迁移时出现此错误
django.db.utils.OperationalError: (2005, "Unknown MySQL server host 'db' (-2)") ERROR: Service 'web' failed to build: The command '/bin/sh -c python manage.py makemigrations' returned a non-zero code: 1
here is my Dockerfile这是我的 Dockerfile
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /SFP_ingestion
WORKDIR /SFP_ingestion
COPY . /SFP_ingestion
RUN pip install -r requirements.txt
RUN python generatemodel.py
RUN python generateapp.py
RUN python manage.py makemigrations
RUN python manage.py migrate
RUN python manage.py migrate easyaudit
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
and here is my docker-compose.yml这是我的 docker-compose.yml
services:
db:
image: mysql
restart: always
command: --default-authentication-plugin=mysql_native_password --mysqlx=0
environment:
- MYSQL_HOST=localhost
- MYSQL_PORT=3306 # cannot change this port to other number
- MYSQL_DATABASE=sfp # name you want for the database
- MYSQL_USER=root # change to whatever username you want
- MYSQL_PASSWORD=password #change to the password you want for user
- MYSQL_ROOT_PASSWORD=password #change to good root password
ports:
- "3306:3306"
expose:
- "3306"
volumes:
- "./db:/var/lib/mysql"
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/SFP_ingestion
restart: always
ports:
- "8000:8000"
depends_on:
- db
You have to specify network for your containers.您必须为容器指定网络。 https://docs.docker.com/compose/networking/
https://docs.docker.com/compose/networking/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.