EC2上的RSelenium和Docker [英] RSelenium and Docker on EC2

查看:111
本文介绍了EC2上的RSelenium和Docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的最终目标是能够使用









解决方案

以下对我有用。



创建安装了Docker的EC2 Ubuntu实例。我没有使用Windows。



按如下所示在EC2实例上运行硒docker镜像

  docker run -d -p 4445:4444 selenium / standalone-firefox:2.53.0 

通过在安全组中创建适当的条目来确保从运行R的IP地址打开端口4445。



在我的台式机上,可以看到EC2实例,使用此R代码进行连接...

  library(RSelenium)
remDr<-remoteDriver (remoteServerAddr = ec2-xxx.eu-west-1.compute.amazonaws.com,端口= 4445L)
remDr $ open()

#[1]连接到远程服务器
#$ applicationCacheEnabled
#[1]是

#$可旋转
#[1]否

#bhandlesAlerts
#[1]是
#...

请注意EC2实例为 ec2 ...。该地址可从AWS控制台获得,并且是实例的公共DNS名称。如果您恰巧在另一台AWS机器上运行R,则可能需要使用私有DNS地址。





查找Selenium容器的IP地址。一种方法是按以下方式登录

  docker exec -it<容器名称> bash 
主机名-i
退出

在同一EC2机器上运行Rstudio作为Selenium,一种选择是使用Docker。好的图片是 rocker / rstudio



执行以下操作。

  docker run -d -p 8787 :8787 -e PASSWORD =<密码> --name rstudio rocker / rstudio 

请确保要访问的端口8787对您开放Rstudio。在实例的安全组中添加条目。



要在Rstudio docker容器中安装RSelenium,请执行以下操作。

  docker exec rstudio bash 
apt-get update
apt-get install -y libxml2-dev
exit

找到Rstudio GUI的URL-这将是这样的

  http:// ec2-xxx:8787 

用户名是rstudio,密码是您启动容器时指定的密码。



从Rstudio安装RSelenium软件包。

  install.packages( RSelenium)

最后运行R代码以访问Selenium实例。

  library(RSelenium)
remDr<-remoteDriver(remoteServerAddr = Selenium容器的IP地址,端口= 4445L)
remDr $ open()


My final goal is to be able to use through my EC2 instance (AWS).

For that, I read that it is recommeneded to use and install a docker on a virtual machine. So I followed all the steps given by John D Harrison here: https://rpubs.com/johndharrison/RSelenium-Docker

And everything went fine except at the end when I enter in RStudio on my EC2 instance. Because when I try to connect to the remote server I get the below error:

library(RSelenium) remDr <- remoteDriver(remoteServerAddr = "192.168.99.100", port = 4445L) remDr$open()

1 "Connecting to remote server" Error in checkError(res) : Undefined error in httr call. httr output: Timeout was reached: Connection timed out after 10001 milliseconds

I followed the exact steps given in the tutorial so I really don't know what is wrong.

Any help much appreciated !

M.

EDIT1: Please find below screenshots of what I have so far:

My EC2 instance I use is the following:

解决方案

The following works for me.

Create an EC2 Ubuntu instance with Docker installed. I didn't use Windows.

Run the selenium docker image on the EC2 instance as follows

docker run -d -p 4445:4444 selenium/standalone-firefox:2.53.0 

Ensure port 4445 is open from the IP address where you are running R by creating the appropriate entry in the security group.

On my desktop machine that can see the EC2 instance, use this R code to connect...

library(RSelenium)
remDr <- remoteDriver(remoteServerAddr = "ec2-xxx.eu-west-1.compute.amazonaws.com", port = 4445L)
remDr$open()

#[1] "Connecting to remote server"
#$applicationCacheEnabled
#[1] TRUE

#$rotatable
#[1] FALSE

#$handlesAlerts
#[1] TRUE
#...

Note the address of the EC2 instance is "ec2...". This address is available from the AWS console and is the public DNS name of the instance. If you happen to be running R on another AWS machine, then you would probably need to use the private DNS address.

[Edited to add instructions for running Rstudio in the cloud]

Find the IP address of the Selenium container. One way is to log into it as follows

docker exec -it <nameofthecontainer> bash
hostname -i
exit

To run Rstudio on the same EC2 machine as Selenium, one option is to use Docker. A good image is rocker/rstudio.

Do the following.

docker run -d -p 8787:8787 -e PASSWORD=<password> --name rstudio rocker/rstudio

Make sure port 8787 is open to you from where you want to access Rstudio. Add entries in the security group for the instance to do this.

To install RSelenium in the Rstudio docker container, do the following.

docker exec rstudio bash
apt-get update
apt-get install -y libxml2-dev
exit

Find the URL of the Rstudio GUI - it will be something like this

http://ec2-xxx:8787 

The username is rstudio and the password is whatever you specified when you started the container.

Install the RSelenium package from Rstudio.

install.packages("RSelenium")

Finally run the R code to access the Selenium instance.

library(RSelenium)
remDr <- remoteDriver(remoteServerAddr = "IP address of the Selenium container", port = 4445L)
remDr$open()

这篇关于EC2上的RSelenium和Docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆