1、拉取浏览器镜像
docker pull selenoid/vnc:chrome_103.0
2、拉取selenoid-ui容器镜像
docker pull aerokube/selenoid-ui:1.10.4
3、拉取selenoid容器镜像
docker pull aerokube/selenoid
4、编写配置文件 vi /selenoid/config/browsers.json
volumes可以做容器路径映射,让浏览器容器访问本地的文件
env可以指定一些环境变量,比如设置浏览器语言、时区
shmSize浏览器共享内存大小,默认值256Mb,设置的太小可能出现不稳定的情况(浏览器崩溃、闪退等),设置的太大占用的服务器会资源更多
{
"chrome": {
"default": "103.0",
"versions": {
"chrome_104": {
"image": "selenoid/vnc:chrome_104.0",
"privileged": "true",
"volumes": ["/data:/boot"],
"port": "4444",
"path": "/",
"shmSize": 1073741824,
"mem": "1024m",
"env": ["LANG=chn_CHN.UTF-8", "LANGUAGE=chn:zh", "LC_ALL=chn_CHN.UTF-8", "TZ=Asia/Shanghai"]
},
"chrome_103": {
"image": "selenoid/vnc:chrome_103.0",
"privileged": "true",
"volumes": ["/data:/boot"],
"port": "4444",
"path": "/",
"env": ["LANG=chn_CHN.UTF-8", "LANGUAGE=chn:zh", "LC_ALL=chn_CHN.UTF-8"]
},
"firefox_103": {
"image": "selenoid/vnc:firefox_103.0",
"privileged": "true",
"volumes": ["/data:/boot"],
"port": "4444",
"path": "/",
"env": ["LANG=chn_CHN.UTF-8", "LANGUAGE=chn:zh", "LC_ALL=chn_CHN.UTF-8"]
}
}
}
}
5、启动selenoid容器
docker run -d --name selenoid -p 5555:4444 -v /var/run/docker.sock:/var/run/docker.sock -v /selenoid/config/:/etc/selenoid/:ro aerokube/selenoid -limit 10 -timeout 30s
6、启动selenoid-ui
docker run -d --name selenoid-ui -p 8080:8080 aerokube/selenoid-ui:1.10.4 --selenoid-uri http://10.7.163.249:5555
如图:
配合selenium来用非常nice