CentOS7 Docker安装及网络环境配置含Seleniumdocker使用
2021/10/20 7:09:49
本文主要是介绍CentOS7 Docker安装及网络环境配置含Seleniumdocker使用,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Centos7安装
网络环境准备
----------------------------------------------------------------------------------------------------
//更新DNS,防止DNS解析有问题,更换阿里公共DNS sevver
vi /etc/resolv.conf
增加nameserver 223.5.5.5
保存后,锁住文件防止重启被更新掉
chattr +i /etc/resolv.conf
reboot
更换yum镜像源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
---------------------------------------------------------------------------------------------
卸载旧版本 yum -y remove docker docker-common docker-selinux docker-engine
1、yum install -y yum-utils
2、yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
3、yum-config-manager --enable docker-ce-nightly
4、yum-config-manager --enable docker-ce-test
5、yum install docker-ce docker-ce-cli containerd.io
6、systemctl start docker
#配置阿里云加速器,https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 登录进去镜像工具-->镜像加速器-->复制加速地址替换下面的
mkdir -p /etc/docker
vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://pcocmgfc.mirror.aliyuncs.com"]
}
systemctl daemon-reload
systemctl restart docker
docker selenium chrome
docker pull selenium/hub
docker pull selenium/node-chrome
后台启动主hub后台运行容器4444转到宿主机8888
docker run -d -p 8888:4444 --name selenium-hub selenium/hub
启动分支node chrome 容器
docker run -d --link selenium-hub:hub selenium/node-chrome
启动后查看容器id 通过id查看log,log中会有chrome的驱动版本,以及selenium的版本
查看log 命令 docker logs -t 容器id
自己代码只要selenium的版本对应查到的版本即可
注每次docker run会产生对应的容器实例,如果宿主机被重启,可以先删除之前的实例容器id
先启动docker systemctl restart docker
强制删除实例化的容器 docker rm -f $(docker ps -aq)
然后再启动主从
后台启动主hub后台运行容器4444转到宿主机8888
docker run -d -p 8888:4444 --name selenium-hub selenium/hub
启动分支node chrome 容器
docker run -d --link selenium-hub:hub selenium/node-chrome
public static void main(String[] args){
try{
//第一个参数:表示服务器的地址。第二个参数:表示预期的执行对象,其他的浏览器都可以以此类推,ip和端口对应宿主机的ip和容器转发宿主机的端口
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.88.129:8888/wd/hub/"), DesiredCapabilities.chrome());
driver.manage().window().maximize();
driver.get("http://www.baidu.com");
Thread.sleep(2000);
System.out.println("Title----"+driver.getTitle());
Thread.sleep(2000);
driver.quit();
}catch(Exception e){
e.printStackTrace();
}
}
=======================================================================================
maven工程打依赖包配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.web.test</groupId>
<artifactId>WebTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<!--配置程序入-->
<mainClass>com.web.test.WebTest</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<includeProjectDependencies>true</includeProjectDependencies>
<includePluginDependencies>false</includePluginDependencies>
<classpathScope>compile</classpathScope>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
这篇关于CentOS7 Docker安装及网络环境配置含Seleniumdocker使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24Docker环境部署教程:新手入门详解
- 2024-12-24Docker环境部署项目实战教程
- 2024-12-24Docker环境部署学习:初学者指南
- 2024-12-24Docker环境部署入门:新手必读指南
- 2024-12-20Docker部署资料:新手入门教程
- 2024-12-19Docker部署实战:新手入门教程
- 2024-12-19Docker部署教程:新手入门详解
- 2024-12-09云原生周刊:在Docker上部署大语言模型
- 2024-12-05Docker教程:新手快速入门指南
- 2024-12-05Docker项目实战:新手教程与案例解析