【DevOps】常用的 dockerfile 集锦

dockerfile中 apt 安装包

RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list \
&& apt-get clean \
&& apt-get update \
&& apt install -y ffmpeg \
&& apt clean

python3.8 + selenium

FROM 120.xxx.xx.189:5000/python:3.8

RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone

RUN wget -q -O - https://dl.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 && apt-get install -y google-chrome-stable && 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

爬虫代码需要设置如下三个参数

from selenium import webdriver

option = webdriver.ChromeOptions()
option.add_argument('-headless')
option.add_argument('-no-sandbox')
option.add_argument('–disable-dev-shm-usage')

driver = webdriver.Chrome(options=option)

ubuntu18.04 + java1.8

FROM 120.xxx.xx.189:5000/ubuntu:18.04

ADD jdk-8u111-linux-x64.tar.gz /usr/local/java/
ENV JAVA_HOME /usr/local/java/jdk1.8.0_111
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV PATH $JAVA_HOME/bin:$PATH

ubuntu18.04 + java1.8 + python3.8

FROM harbor_ip:port/ubuntu:18.04

FROM harbor_ip:port/ubuntu:18.04

ADD jdk-8u111-linux-x64.tar.gz /usr/local/java/
ENV JAVA_HOME /usr/local/java/jdk1.8.0_111
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV PATH $JAVA_HOME/bin:$PATH

RUN apt update && apt install -y python3.8 && apt install -y python3-distutils && apt install -y wget && apt clean

RUN ln -s /usr/bin/python3.8 /usr/bin/python

RUN wget https://bootstrap.pypa.io/get-pip.py

RUN python get-pip.py

python3.8 + selenium + nodejs

1、下载nodejs:https://nodejs.org/en/download/current/

2、解压

sudo xz -d node-v16.11.0-linux-x64.tar.xz 

sudo tar -xvf node-v16.11.0-linux-x64.tar

3、建立软链

sudo ln -s /usr/node-v16.11.0-linux-x64/bin/node /usr/local/bin/node

sudo ln -s /usr/node-v16.11.0-linux-x64/bin/npm /usr/local/bin/npm

4、验证

npm -v
node -v

dockerfile实现

FROM harbor_ip:port/copyright_monitor/python:3.8

RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone

RUN wget -q -O - https://dl.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 && apt-get install -y google-chrome-stable && 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 ./ /usr/scrapyd-spider

RUN tar -xvJf /usr/scrapyd-spider/node-v16.11.0-linux-x64.tar.xz -C /usr/scrapyd-spider/ && rm -f /usr/scrapyd-spider/node-v16.11.0-linux-x64.tar.xz

RUN ln -s /usr/scrapyd-spider/node-v16.11.0-linux-x64/bin/node /usr/local/bin/node && ln -s /usr/scrapyd-spider/node-v16.11.0-linux-x64/bin/npm /usr/local/bin/npm

RUN pip install --no-cache-dir -r /usr/scrapyd-spider/ScrapydSpider/requirements.txt -i  https://pypi.tuna.tsinghua.edu.cn/simple/

RUN cp  /usr/scrapyd-spider/ScrapydSpider/default_scrapyd.conf /usr/local/lib/python3.8/site-packages/scrapyd/default_scrapyd.conf

WORKDIR /usr/scrapyd-spider/ScrapydSpider/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值