构建一个有桌面、能自动跑有头浏览器的Docker

一、Docker

Docker + Ubuntu + noVNC + FastAPI + Playwright 构建浏览器自动化测试

  1. Dockerfile
FROM fredblgr/ubuntu-novnc:20.04

# 使用中国时区
ENV TZ=Asia/Shanghai \
    DEBIAN_FRONTEND=noninteractive
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

# 设置清华源
# RUN sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list

# 更新软件包列表并安装所需软件
RUN apt-get update 
RUN apt-get install -y vim net-tools
RUN apt-get install -y python3 pip
RUN pip install requests faker playwright fastapi uvicorn cf-clearance redis
RUN python -m playwright install chromium

# 设置默认的工作目录
WORKDIR /root

# 将当前目录的所有内容复制到镜像的工作目录
# COPY . .

# 暴露的端口
EXPOSE 80 8099 443 22

# 启动时执行的命令
# CMD ["bash"]
  1. 构建镜像
docker build -t autobrowser .
  1. 生成容器并启动
docker run -d -p 6080:80 -p 8099:8099 -e HTTP_PASSWORD=123456 -e RESOLUTION=1366x768 --name autobrowser autobrowser

这个docker中已经装好了Ubuntu、noVNC、Python3.8.5、FastAPI、Playwright。

noVNC的界面地址:
http://127.0.0.1:6080/
FastAPI服务地址:
http://127.0.0.1:8099/

posted @ 2023-07-07 16:25  anyiya  阅读(172)  评论(0编辑  收藏  举报