In the last post, we installed docker on our local ubuntu 16.04
Now let's create an own image with a complete selenium testenviroment on it.
Prerequisits
Installed DockerAn account on docker hub (https://www.docker.com/)
Pull an Ubuntu 16.04 image
We want to install Selenium on a lunux ubuntu image. So we have to pull this image first.$ sudo docker pull ubuntu:14.04
$ sudo docker images
The first command downloads the ubuntu base image, we want to use.
The second command "images" shows us the newly installed image. Please remember the Image ID. You will need it now
Create a new container
Use Run to create a new container
"Run" is used to create a new container.
You can type:
$ sudo docker run --help
to get all supported options.
For our first image we want to use:
$ docker run-i -t <your ubuntu image id> /bin/bash
This tells docker to create a container and open a shell on it, so that we can install our selenium tools.
Now you have a console on the ubuntu machine.
You can type "exit" to get back to the host.
Start the new container
After you have created your container, you can list all containers with$ docker ps
This will output your running processes:
You now see your container id in the left
To start our container we type:
$ docker start <your container id>
Bind a shell to the container
At nex we want to bind a shell on our new container with:$ docker attach <your container id>
The next input will be on the container
Install Selenium 3.0
After we have binded a shell on the new container, we install our testenviroment on the container$ apt-get update
Install Java
$ apt-get install openjdk-8-jdk
This could take a while.....
Install wget
$ apt-get install wget
Download and install selenium
$ mkdir /usr/lib/selenium
$ wget --output-document=selenium-server-standalone-3.0.0-beta2.jar http://goo.gl/2lZ46z
$ chmod
This will download the selenium server and set executable accessrights
You should have a look for the current downloadurl of selenium under
http://www.seleniumhq.org/download/
Install Selenium as a service
To install the new selium server as a service you only have to save follwing script under "/etc/init.d/selenium"
Make script rebootsave
$ update-rc.d selenium defaults
Create logfiles
$ mkdir -p /var/log/selenium
$ touch /var/log/selenium/selenium-output.log
Install gecko webdriver for firefox
$ cd /usr/lib/selenium$ wget https://github.com/mozilla/geckodriver/releases/download/v0.10.0/geckodriver-v0.10.0-linux64.tar.gz
$ tar xfvz geckodriver-v0.10.0-linux64.tar.gz
$ mv geckodriver-v0.10.0-linux64.tar.gz geckodriver
Install firefox
$ apt-get install firefoxInstall webdriver for chrome
$ cd /usr/lib/selenium$ wget http://chromedriver.storage.googleapis.com/2.23/chromedriver_linux64.zip
$ apt-get install unzip
$ unzip chromedriver_linux64.zip
$ rm -rf chromedriver_linux64.zip
Install headless browsing
To use headless browser we need xvfb. Headless means, that our server has no UI like a desktop machine. So the browser needs to be started "headless"$ apt-get install xvfb
$ Xvfb :10 -ac
$ export DISPLAY=:10
Test selenium server
To test, if the serviceinstallation worked, you can simply type:$ /etc/init.d/selenium start
Commit your container to the docker hub
Your installation on the container is now complete. You now can commit and push it to docker$ docker login
Now you have to enter you accessdata
$ docker commit -m "add selenium server" <your dockerid><your imageid>
$ docker push <your dockerid>
Thats it. Your new image is avalable in the docker hub
Keine Kommentare:
Kommentar veröffentlichen