phantomjs是一个无界面的浏览器,可用于在后端去生成PDF文件。
以下是笔者经过实践可用的镜像脚本Dockerfile,包含phantomjs和nodejs环境
当前目录创建sources.list文件,用于替换debian的镜像源为国内镜像,内容如下
- deb https://mirrors.tencent.com/debian/ bullseye main non-free contrib
- deb-src https://mirrors.tencent.com/debian/ bullseye main non-free contrib
- deb https://mirrors.tencent.com/debian-security/ bullseye-security main
- deb-src https://mirrors.tencent.com/debian-security/ bullseye-security main
- deb https://mirrors.tencent.com/debian/ bullseye-updates main non-free contrib
- deb-src https://mirrors.tencent.com/debian/ bullseye-updates main non-free contrib
- deb https://mirrors.tencent.com/debian/ bullseye-backports main non-free contrib
- deb-src https://mirrors.tencent.com/debian/ bullseye-backports main non-free contrib
去官方下载node v16.17.0 linux x64版本压缩包,文件名应该类似:
node-v16.17.0-linux-x64.tar.xz,放到当前目录。
去phantomjs官网下载安装包,下载地址:phantomjs-2.1.1-linux-x86_64.tar.bz2
下载后解压后,将bin目录下的phantomjs文件拷到当前目录
当前目录新建Dockerfile文件,内容如下
- FROM debian:stable-slim
- RUN apt-get update
- RUN apt-get install -y apt-transport-https ca-certificates
-
- #mirror
- COPY sources.list /etc/apt/sources.list
-
- #phantomjs
- RUN apt-get update
- RUN apt-get install -y libfontconfig1
- ENV OPENSSL_CONF /etc/ssl/
- COPY phantomjs /usr/local/bin
-
- #nodejs
- workdir /usr/local/lib/nodejs
- COPY node-v16.17.0-linux-x64.tar.xz ./
- RUN apt-get install -y xz-utils
- RUN tar -xJvf node-v16.17.0-linux-x64.tar.xz -C /usr/local/lib/nodejs
- ENV PATH /usr/local/lib/nodejs/node-v16.17.0-linux-x64/bin:$PATH
- RUN rm -f node-v16.17.0-linux-x64.tar.xz
当前目录下应有如下几个文件
![]()
运行命令构建: docker build -t phantomjs:test .
docker run -it --rm phantomjs:test sh
#phantomjs
如果出现如下提示即说明phantomjs安装成功可用

#node
如果出现如下提示说明nodejs安装成功
