browserless docker 镜像简单说明
browserless docker 镜像默认安装了一些字体文件,对于我们日常使用基本够用了,了解下docker 镜像的制作,可以更好的使用以及配置browserless
简单说明
browserless docker 镜像包含了基础镜像以及不同浏览器的,基础镜像主要提供基础包的安装,不同浏览器的主要是对于不同浏览器的安装以及字体文件的处理
- base 镜像
包含了node以及一些依赖文件的copy,当然还有依赖软件的安装系统用户
FROM ubuntu:20.04
LABEL org.opencontainers.image.source https://github.com/browserless/browserless
ARG DEBIAN_FRONTEND=noninteractive
ARG TZ=America/Los_Angeles
ARG BLESS_USER_ID=999
ARG APP_DIR=/usr/src/app
ARG NODE_VERSION=v20.12.0
ENV NODE_VERSION=$NODE_VERSION
ENV NVM_DIR /usr/src/.nvm
ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION/bin
ENV PATH $NODE_PATH:$PATH
ENV APP_DIR=$APP_DIR
ENV TZ=$TZ
ENV DEBIAN_FRONTEND=$DEBIAN_FRONTEND
ENV HOST=0.0.0.0
ENV PORT=3000
ENV LANG="C.UTF-8"
ENV NODE_ENV=production
ENV DEBUG_COLORS=true
ENV PUPPETEER_SKIP_DOWNLOAD=true
ENV PLAYWRIGHT_BROWSERS_PATH=/usr/local/bin/playwright-browsers
RUN mkdir -p $APP_DIR $NVM_DIR
WORKDIR $APP_DIR
COPY assets assets
COPY bin bin
COPY extensions extensions
COPY external external
COPY scripts scripts
COPY static static
COPY CHANGELOG.md .
COPY LICENSE .
COPY NOTICE.txt .
COPY package.json .
COPY package-lock.json .
COPY README.md .
COPY tsconfig.json .
RUN apt-get update && apt-get install -y \
ca-certificates \
curl \
dumb-init \
git \
gnupg \
libu2f-udev \
software-properties-common \
ssh \
wget \
xvfb
RUN curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash &&\
. $NVM_DIR/nvm.sh &&\
nvm install $NODE_VERSION
RUN add-apt-repository universe && apt-get update && \
apt-get install -y python3.10 python3-pip && \
update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 && \
update-alternatives --install /usr/bin/python python /usr/bin/python3 1
RUN groupadd -r blessuser && useradd --uid ${BLESS_USER_ID} -r -g blessuser -G audio,video blessuser && \
mkdir -p /home/blessuser/Downloads && \
chown -R blessuser:blessuser /home/blessuser
RUN npm i --production=false
- 浏览器的
包含了browserless rest api 服务代码的copy,同时包含了不少字体文件的处理,整体来说核心是字体文件
ARG VERSION=latest
FROM ghcr.io/browserless/base:$VERSION
LABEL org.opencontainers.image.source https://github.com/browserless/browserless
COPY fonts/* /usr/share/fonts/truetype/
COPY src src/
RUN rm -r src/routes/
COPY src/routes/management src/routes/management/
COPY src/routes/chromium src/routes/chromium/
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections && \
apt-get -y -qq install software-properties-common &&\
apt-add-repository "deb http://archive.canonical.com/ubuntu $(lsb_release -sc) partner" && \
apt-get -y -qq --no-install-recommends install \
fontconfig \
fonts-freefont-ttf \
fonts-gfs-neohellenic \
fonts-indic \
fonts-ipafont-gothic \
fonts-kacst \
fonts-liberation \
fonts-noto-cjk \
fonts-noto-color-emoji \
fonts-roboto \
fonts-thai-tlwg \
fonts-ubuntu \
fonts-wqy-zenhei
RUN npx --yes playwright install chromium &&\
npx --yes playwright install-deps chromium &&\
npm run build &&\
npm run build:function &&\
npm prune production &&\
chown -R blessuser:blessuser $APP_DIR &&\
fc-cache -f -v && \
apt-get -qq clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/fonts/truetype/noto
USER blessuser
CMD ["./scripts/start.sh"]
说明
以上是一个简单说明,学习下browserless docker file 的制作可以更好的使用browserless
参考资料
docker/chromium/Dockerfile
https://github.com/browserless/browserless
https://github.com/browserless/browserless/tree/main/docker