Ubuntu_amd64容器化部署chromedriver的過程

济南小老虎發表於2024-04-05

Ubuntu_amd64容器化部署chromedriver的過程


獲取部分資料

其他版本需要自己選擇下載: 
https://chromedriver.com/download
老版本:
https://old.chromedriver.com/index.html
https://www.chromedownloads.net/chrome64linux-stable/

docker pull ubuntu:2404
wget https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.105/linux64/chrome-linux64.zip
wget https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.105/linux64/chromedriver-linux64.zip

unzip chrome-linux64.zip chromedriver-linux64.zip
scp chromedriver-linux64/chromedriver chrome-linux64/

mkdir -p /ubuntu
scp -r chrome-linux64 /ubuntu 
mv  /ubuntu/chrome-linux64 /ubuntu/bin  

其他版本-Windows

https://downzen.com/en/windows/google-chrome/versions/?page=1

編寫dockerfile

FROM ubuntu:24.04
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive TZ="Asia/Shanghai"  \
apt-get  install -y libasound2 libxfixes3  \
libcairo2 libpango-1.0-0 libxkbcommon0 libgbm1 libxrandr2 \
libxdamage1 libxcomposite1 libdrm2 libcups2 libatk-bridge2.0-0  \
libglib2.0-0  libnss3 libdbus-1-3 libatk1.0-0 && apt-get clean
COPY bin /usr/bin/
ADD python3.12.2_amd64.tar.gz /opt

映象打包命令

docker build . -t ubuntu:2404chrome123

版本驗證

docker run -it ubuntu:2404chrome123 bash
root@1381c6d15553:/# /opt/python3/bin/python3 -V
Python 3.12.2
root@1381c6d15553:/# /opt/python3/bin/pip3 -V
pip 24.0 from /opt/python3/lib/python3.12/site-packages/pip (python 3.12)
root@1381c6d15553:/# chrome --version
Google Chrome for Testing 123.0.6312.105
root@1381c6d15553:/# chromedriver -v
ChromeDriver 123.0.6312.105 
root@1381c6d15553:/# lscpu |grep x86
Architecture:                    x86_64

依賴解決方案

最簡單的辦法: 先打包一箇中間映象
FROM ubuntu:24.04
RUN apt-get update
COPY bin /usr/bin/

docker build . -t ubuntu:temp

apt-get install apt-file -y 
apt-file update
apt-file search libdbus-1.so.3

相關文章