当 运行 docker 仅在 M1 mac 上构建时,为什么会出现 pip 安装错误

Why get pip install error, when run docker build on only M1 mac

我正在使用 Intel 和 Apple Silicon 芯片 Mac。

当我在 Intel Mac 上构建 dockerfile 时,它是成功的。当我在 M1 Mac 上构建相同的文件时,如何出现此错误。


#10 3.254 ERROR: Could not find a version that satisfies the requirement google-python-cloud-debugger (from versions: none)
#10 3.255 ERROR: No matching distribution found for google-python-cloud-debugger
------
executor failed running [/bin/sh -c python -m pip install --upgrade pip && pip install -r requirements.txt]: exit code: 1

这不仅仅是google-python-cloud-debugger。如果我删除它,另一个模块会遇到同样的错误。

如何解决这个问题?

我的requirements.txtdockerfile在下面。

gunicorn==19.9.0
selenium==3.141.0
webdriver-manager==3.5.2
google-python-cloud-debugger
google-cloud-storage
django==3.2
mysqlclient==2.1.0
pysqlite3==0.4.6
django-storages==1.12.3
Pillow==9.0.0
requests==2.27.1
FROM python:3.9-buster

# Install manually all the missing libraries
RUN apt-get update && apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget fonts-takao-*

# Install Chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install

# Install Python dependencies.
COPY requirements.txt requirements.txt
RUN python -m pip install --upgrade pip && pip install -r requirements.txt

# Copy chrome driver
COPY drivers /root/.wdm/drivers

# Copy local code to the container image.
COPY . /app
ENV APP_HOME /app/website
WORKDIR $APP_HOME

# Run the web service on container startup. Here we use the gunicorn
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 website.wsgi

我解决了这个问题!当我们在 M1 Mac 上构建 dockerfile 时,我们需要指定 platform。所以需要在dockerfile的FROM之后添加--platform=linux/x86_64

例子

FROM --platform=linux/x86_64 python:3.9-buster