請注意,我已經從 Windows 機器的 Microsoft 商店安裝了 ubuntu20.04。
我想在容器內執行所有操作,并希望在我的本地系統中使用 zip 檔案,但 pushd 正在尋找本地目錄。請建議。
#!/bin/bash
RUNTIME=python3.7
SELENIUM_VER=3.141.0
CHROME_BINARY_VER=v1.0.0-55 # based on Chromium 69.0.3497.81
CHROMEDRIVER_VER=2.43 # supports Chrome v69-71
#mkdir -p out/build/chrome_headless/python/lib/$RUNTIME/site-packages
OUT_DIR=out/build/chrome_headless/python/lib/$RUNTIME/site-packages
docker run -v $(pwd):/out -it lambci/lambda:build-$RUNTIME pip install selenium==$SELENIUM_VER --target $OUT_DIR
pushd build/chrome_headless
DRIVER_URL=https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VER/chromedriver_linux64.zip
curl -SL $DRIVER_URL >chromedriver.zip
unzip chromedriver.zip
rm chromedriver.zip
# download chrome binary
CHROME_URL=https://github.com/adieuadieu/serverless-chrome/releases/download/$CHROME_BINARY_VER/stable-headless-chromium-amazonlinux-2017-03.zip
curl -SL $CHROME_URL >headless-chromium.zip
unzip headless-chromium.zip
rm headless-chromium.zip
zip -r ../../chrome_headless.zip *
錯誤:
正在收集 selenium==3.141.0 正在下載 selenium-3.141.0-py2.py3-none-any.whl (904 kB) 904 kB 1.8 MB/s 正在收集 urllib3 正在下載 urllib3-1.26.8-py2.py3-none-any。 whl (138 kB) 138 kB 5.9 MB/s 安裝收集的包:urllib3, selenium 成功安裝 selenium-3.141.0 urllib3-1.26.8 警告:您使用的是 pip 版本 21.0;但是,版本 22.0.3 可用。您應該考慮通過“/var/lang/bin/python3.7 -m pip install --upgrade pip”命令進行升級。./docker-script-layer-linux.sh: 第 16 行: pushd: build/chrome_headless: 沒有這樣的檔案或目錄 % Total % Received % Xferd 平均速度 時間 時間 當前 Dload 上傳總花費 左速度 100 3987k 100 3987k 0 0 7250k 0 --:--:-- --:--:-- --:--:-- 7236k ./docker-script-layer-linux.sh: line 20: unzip: command not found % Total % Received % Xferd Average Speed Time
Time Time Current Dload Upload Total Spent Left Speed 100 685 100 685 0 0 1495 0 --:- -:-- --:--:-- --:--:-- 1498 100 43.4M 100 43.4M 0 0 9496k 0 0:00:04 0:00:04 --:--:-- 10.3米
uj5u.com熱心網友回復:
我正在使用下面的 dockerfile 來完成上述任務
FROM lambci/lambda:python3.7
ENV SELENIUM_VER=3.141.0
#based on Chromium 69.0.3497.81
ENV CHROME_BINARY_VER=v1.0.0-55
# supports Chrome v69-71
ENV CHROMEDRIVER_VER=2.43
ENV RUNTIME=python3.7
USER root
SHELL ["/bin/bash", "-c"]
RUN yum -y install zip unzip
# Directory in container for project source files
ENV OUT_DIR=/out/build/chrome_headless/python/lib/$RUNTIME/site-packages
# Install Python dependencies
RUN mkdir -p $OUT_DIR
RUN pip install selenium==$SELENIUM_VER --target $OUT_DIR
WORKDIR /out/build/chrome_headless
ENV DRIVER_URL=https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VER/chromedriver_linux64.zip
RUN curl -SL $DRIVER_URL >chromedriver.zip
RUN dir
RUN unzip chromedriver.zip
RUN rm chromedriver.zip
# download chrome binary
ENV CHROME_URL=https://github.com/adieuadieu/serverless-chrome/releases/download/$CHROME_BINARY_VER/stable-headless-chromium-amazonlinux-2017-03.zip
RUN curl -SL $CHROME_URL >headless-chromium.zip
RUN unzip headless-chromium.zip
RUN rm headless-chromium.zip
RUN zip -r chrome_headless.zip *
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/432243.html
下一篇:如何將變數分配給引號中的每個值
