NLO*_*day 3 mysql django docker alpine-linux
FROM python:3.6.5-alpine3.7
WORKDIR /app
ADD . /app
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 10021
CMD ["python", "manage.py", "runserver", "0.0.0.0:10021"]
Run Code Online (Sandbox Code Playgroud)
要求
Collecting mysqlclient==1.3.12 (from -r requirements.txt (line 4))
Downloading https://mirrors.aliyun.com/pypi/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.tar.gz (89kB)
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-er3m_9t6/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-install-er3m_9t6/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-install-er3m_9t6/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
Run Code Online (Sandbox Code Playgroud)
感谢@danblack对于mariadb-connector-c-dev这帮助我解决这个OSError: mysql_config not found错误。
FROM python:3.6.5-alpine3.7
WORKDIR /app
ADD . /app
RUN apk add --no-cache build-base && apk add --no-cache mariadb-connector-c-dev && pip install --no-cache-dir -r requirements.txt && apk del build-base
EXPOSE 10021
CMD ["python", "manage.py", "runserver", "0.0.0.0:10021"]
Run Code Online (Sandbox Code Playgroud)
但是出现了一个新问题,Dockerdocker run ...运行时什么也没打印,没有日志,没有错误。它应该打印如下日志
Performing system checks...
System check identified no issues (0 silenced).
September 04, 2018 - 15:56:26
Django version 2.0.2, using settings 'xxx.settings'
Starting development server at http://0.0.0.0:10021/
Quit the server with CTRL-BREAK.
Run Code Online (Sandbox Code Playgroud)
有人可以给我看一个完整的 Dockerfile 吗?请帮忙!非常感谢。
根据@danblack,主要需要安装mariadb-connector-c-dev包。但只有这个包才会出现编译错误。因此,您还需要将 gcc 和 musl-dev 包添加到 Dockerfile 中。这将使 Django 和 MySQL 在 alpine 镜像中工作。
FROM python:3.8-alpine
RUN apk add gcc musl-dev mariadb-connector-c-dev
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3174 次 |
| 最近记录: |