docker mysql django_无法为Django和Mysql触发Docker构建

我正在用Djnago和MySql构建应用程序。我想使用docker来部署我的应用程序。我已经准备了一个requirement.txt,docker-

compose.yml和Dockerfile

docker-compose.yml

version: "3"

services:

law-application:

restart: always

build:

context: .

ports:

- "8000:8000"

volumes:

- ./app:/app

command: >

sh -c "python manage.py runserver 0.0.0.0:8000"

depends_on:

- mysql_db

mysql_db:

image: mysql:latest

command: mysqld --default-authentication-plugin=mysql_native_password

volumes:

- "./mysql:/var/lib/mysql"

ports:

- "3306:3306"

restart: always

environment:

- MYSQL_ROOT_PASSWORD=root

- MYSQL_DATABASE=root

- MYSQL_USER=root

- MYSQL_PASSWORD=root

requirements.txt

django>=2.1.3,<2.2.0

djangorestframework==3.11.0

mysqlclient==1.4.6

Docker文件

FROM python:3.7-alpine

MAINTAINER Intersources Inc.

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /requirements.txt

RUN pip install -r /requirements.txt

RUN apt-get update

RUN apt-get install python3-dev default-libmysqlclient-dev -y

RUN mkdir /app

WORKDIR /app

COPY ./app /app

RUN adduser -D jeet

USER jeet

settings.py

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.mysql',

'NAME': 'my-app-db',

'USER': 'root',

'PASSWORD': 'root',

'HOST': 'mysql_db',

'PORT': 3307,

}

}

我一直在尝试运行命令docker build

.从docker文件构建映像,但出现此错误。看起来MySql连接器有问题。我尝试搜索解决方案,但找不到任何解决方法。如果从中删除 mysql_db

服务,则可以构建映像docker-compose.yml。

Sending build context to Docker daemon 444.7MB

Step 1/12 : FROM python:3.7-alpine

---> 6c7f85a86cca

Step 2/12 : MAINTAINER Intersources Inc.

---> Using cache

---> 03b6fa5764d4

Step 3/12 : ENV PYTHONUNBUFFERED 1

---> Using cache

---> 22ecd91dcb55

Step 4/12 : COPY ./requirements.txt /requirements.txt

---> Using cache

---> e58c16108f20

Step 5/12 : RUN pip install -r /requirements.txt

---> Running in 8f3eb8240fce

Collecting django<2.2.0,>=2.1.3

Downloading https://files.pythonhosted.org/packages/ff/82/55a696532518aa47666b45480b579a221638ab29d60d33ce71fcbd3cef9a/Django-2.1.15-py3-none-any.whl (7.3MB)

Collecting djangorestframework==3.11.0

Downloading https://files.pythonhosted.org/packages/be/5b/9bbde4395a1074d528d6d9e0cc161d3b99bd9d0b2b558ca919ffaa2e0068/djangorestframework-3.11.0-py3-none-any.whl (911kB)

Collecting mysqlclient==1.4.6

Downloading https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz (85kB)

ERROR: Command errored out with exit status 1:

command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-e9kt1otq/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-e9kt1otq/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-e9kt1otq/mysqlclient/pip-egg-info

cwd: /tmp/pip-install-e9kt1otq/mysqlclient/

Complete output (12 lines):

/bin/sh: mysql_config: not found

/bin/sh: mariadb_config: not found

/bin/sh: mysql_config: not found

Traceback (most recent call last):

File "", line 1, in

File "/tmp/pip-install-e9kt1otq/mysqlclient/setup.py", line 16, in

metadata, options = get_config()

File "/tmp/pip-install-e9kt1otq/mysqlclient/setup_posix.py", line 61, in get_config

libs = mysql_config("libs")

File "/tmp/pip-install-e9kt1otq/mysqlclient/setup_posix.py", line 29, in mysql_config

raise EnvironmentError("%s not found" % (_mysql_config_path,))

OSError: mysql_config not found

----------------------------------------

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

The command '/bin/sh -c pip install -r /requirements.txt' returned a non-zero code: 1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值