我使用这个Dockerfile在Docker容器中安装Selenium chromedriver:
FROM python:3.8
# install google chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update
RUN apt-get install -y google-chrome-stable
# install chromedriver
RUN apt-get install -yqq unzip
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
ENV DISPLAY=:99
COPY . /app
WORKDIR /app
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN chmod 755 ./run.sh
ENTRYPOINT ["/app/run.sh"]
我已经使用了这个Dockerfile一段时间前,一切工作正常。现在,当我运行
时,我得到了这个错误:docker build -t container .
生成时的错误:
[+] Building 2.8s (9/17)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 818B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/python:3.8 2.1s
=> [ 1/13] FROM docker.io/library/python:3.8@sha256:b9f9612dfd39f75b372056ebb50b9888b4ea7ba48e33d2342f7866816723fa 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 46.81kB 0.0s
=> CACHED [ 2/13] RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - 0.0s
=> CACHED [ 3/13] RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/ap 0.0s
=> CACHED [ 4/13] RUN apt-get -y update 0.0s
=> ERROR [ 5/13] RUN apt-get install -y google-chrome-stable 0.7s
------
> [ 5/13] RUN apt-get install -y google-chrome-stable:
#8 0.262 Reading package lists...
#8 0.536 Building dependency tree...
#8 0.599 Reading state information...
#8 0.650 E: Unable to locate package google-chrome-stable
------
executor failed running [/bin/sh -c apt-get install -y google-chrome-stable]: exit code: 100
make: *** [build] Error 1
问题出在哪里?
为什么不直接使用一个已经存在的图像作为你的起点呢?例如,这看起来像chrome和python的功能docker图像:
https://hub.docker.com/r/joyzoursky/python-chromedriver/
这是Mac (Apple Silicon)的解决方案,它可能也适用于其他设备
在你的Dockerfile中使用图像,明确提到linux/amd6使用
FROM --platform=linux/amd64 python:3.8
不是
FROM python:3.8
或
如果使用组合文件,则使用
向图像添加平台services:
app:
platform: linux/x86_64
build:
dockerfile: Dockerfile
...