在mysqlclient的pip安装上将docker构建推送到ECR时出错



我正试图用以下命令(减去构建参数(将python lambda函数的docker构建推送到AWS:

docker build --build-arg PROD_DB_HOST="xxx.us-east-1.rds.amazonaws.com"  -t vbam-etf-change-report .

我的requirements.txt文件的内容:

mysqlclient==2.0.3
python-dotenv

我的Dockerfile的内容(减去程序参数环境变量(:

FROM public.ecr.aws/lambda/python:3.8
# Copy function code
COPY ETFChangeReportlLambda.py ${LAMBDA_TASK_ROOT}
# Avoid cache purge by adding requirements first
COPY requirements.txt ${LAMBDA_TASK_ROOT}
RUN pip install --no-cache-dir -r requirements.txt

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "ETFChangeReportlLambda.handler" ]

错误:

#7 [4/4] RUN pip install --no-cache-dir -r requirements.txt
#7 sha256:1ea7868443d498b5222a02c472168a9dc59c8bdf685330406552a2733ad1f356
#7 0.576 Collecting mysqlclient==2.0.3
#7 0.610   Downloading mysqlclient-2.0.3.tar.gz (88 kB)
#7 0.616      ΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöü 88.9/88.9 KB 27.3 MB/s eta 0:00:00
#7 0.631   Preparing metadata (setup.py): started
#7 0.746   Preparing metadata (setup.py): finished with status 'error'
#7 0.751   error: subprocess-exited-with-error
#7 0.751
#7 0.751   × python setup.py egg_info did not run successfully.
#7 0.751   Γöé exit code: 1
#7 0.751   Γò░ΓöÇ> [16 lines of output]
#7 0.751       /bin/sh: mysql_config: command not found
#7 0.751       /bin/sh: mariadb_config: command not found
#7 0.751       /bin/sh: mysql_config: command not found
#7 0.751       Traceback (most recent call last):
#7 0.751         File "<string>", line 2, in <module>
#7 0.751         File "<pip-setuptools-caller>", line 34, in <module>
#7 0.751         File "/tmp/pip-install-u5vr3ps6/mysqlclient_7d2089be268641c8a9eb33bc95cf2873/setup.py", line 15, in <module>
#7 0.751           metadata, options = get_config()
#7 0.751         File "/tmp/pip-install-u5vr3ps6/mysqlclient_7d2089be268641c8a9eb33bc95cf2873/setup_posix.py", line 70, in get_config
#7 0.751           libs = mysql_config("libs")
#7 0.751         File "/tmp/pip-install-u5vr3ps6/mysqlclient_7d2089be268641c8a9eb33bc95cf2873/setup_posix.py", line 31, in mysql_config
#7 0.751           raise OSError("{} not found".format(_mysql_config_path))
#7 0.751       OSError: mysql_config not found
#7 0.751       mysql_config --version
#7 0.751       mariadb_config --version
#7 0.751       mysql_config --libs
#7 0.751       [end of output]
#7 0.751
#7 0.751   note: This error originates from a subprocess, and is likely not a problem with pip.
#7 0.753 error: metadata-generation-failed
#7 0.753
#7 0.753 × Encountered error while generating package metadata.
#7 0.753 Γò░ΓöÇ> See above for output.
#7 0.753
#7 0.753 note: This is an issue with the package mentioned above, not pip.
#7 0.753 hint: See above for details.
#7 ERROR: executor failed running [/bin/sh -c pip install --no-cache-dir -r requirements.txt]: exit code: 1
------
> [4/4] RUN pip install --no-cache-dir -r requirements.txt:
------
executor failed running [/bin/sh -c pip install --no-cache-dir -r requirements.txt]: exit code: 1

我能对Dockerfile做些什么吗;OSError:myssql_config找不到(错误?

最近也面临同样的问题。您必须在基本映像的顶部安装gccmysql-devel。然后按照这里的建议添加环境变量。所以,最后你的docker文件应该包含:

# Install required development packages and libraries
RUN yum update -y && 
yum install -y gcc mysql-devel

# Set environment variables for mysqlclient
RUN export MYSQLCLIENT_CFLAGS=`pkg-config mysqlclient --cflags` && 
export MYSQLCLIENT_LDFLAGS=`pkg-config mysqlclient --libs`

这将安装所需的软件包,并设置安装mysqlclient所需的环境变量。

我切换到sqlalchemy,这是一个足够好的解决方法。

最新更新