创建Docker映像时无法安装Flask_MySQL软件包

时间:2019-03-04 03:30:09

标签: python-3.x docker dockerfile alpine

尝试在python:alpine基本映像上安装Flask_MySQL软件包时遇到此错误。有人知道为什么会这样吗?

错误:

cc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -Dversion_info=(1,4,2,'post',1) -D__version__=1.4.2.post1 -I/usr/include/mysql -I/usr/include/mysql -I/usr/local/include/python3.7m -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3.7/MySQLdb/_mysql.o
    unable to execute 'gcc': No such file or directory
    error: command 'gcc' failed with exit status 1

Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-jvwb1s5k/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-p8tkehmf/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-jvwb1s5k/mysqlclient/

这是我的docker文件:

FROM python:alpine
COPY . /app
WORKDIR /app
RUN apk add python3-dev
RUN apk add libevent-dev
RUN apk add mysql-client
RUN apk add mariadb-dev
RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt
EXPOSE 5000
CMD python ./app.py

1 个答案:

答案 0 :(得分:0)

必须安装gcc和依赖项 musl-libc