Docker in Automation testing - docker

Can we launch browsers inside containers created with Windows 10 base image?
Currently we use one VM to run one script , which is not a good way of utilising resources.
With container technology is it possible to run multiple IE browser instances in the same VM parallel and independent to each other.
My requirement is a container with one testing tool and a IE browser to run automated test.
Appreciate your help. Thanks.

You can use Docker-Browser-Box
Pull the container
docker pull sameersbn/browser-box:1.0.1-3
Install the wrapper when image locally available.
docker run -it --rm \
--volume /usr/local/bin:/target \
--env BROWSER_BOX_REPO=sameersbn \
sameersbn/browser-box:1.0.1-3 install
This will install wrapper scripts to launch:
chromium-browser
firefox
google-chrome, google-chrome-stable
tor-browser
Then you can just google-chrome {LINK}
Reference: Docker Browser Box README

Related

Storybook changes reload in Docker on Ubuntu, but not Windows Docker Desktop

I have a simple Dockerfile we use solely while developing a React component library that uses Storybook. The configuration simply pulls from node:latest and mounts our project.
Dockerfile
FROM node:latest
EXPOSE 6006
WORKDIR /usr/src/app
COPY . .
RUN npm install
CMD [ "bash" ]
Building and Running
docker build -t <our name> .
docker run --rm -it -p 6006:6006 -v $(pwd):/usr/src/app <our name>
# Inside interactive container
npm run storybook
package.json
{
"scripts": {
"storybook": "start-storybook -p 6006"
}
}
At work, we use Ubuntu and this setup worked as expected.
However while using:
Windows 10 Pro
Git Bash for Windows
Docker Desktop
it seems that no changes to story files are observed. File saves do not trigger any activity in the console, nor in the browser.
Why could this be the case? Is there a problem with our Docker setup that we're missing?
This actually stems from a known problem #56.
Inotify does not work on Docker for Windows
The Docker For Windows Documentation recommends using a poling solution:
Currently, inotify does not work on Docker Desktop for Windows. This becomes evident, for example, when an application needs to read/write to a container across a mounted drive. Instead of relying on filesystem inotify, we recommend using polling features for your framework or programming language.
Example Poling Solution (docker-windows-volume-watcher)
One poling solution is docker-windows-volume-watcher.
Running the below from another terminal in the project directory solves the issue:
docker-volume-watcher <name of running container> $(pwd)

How to disable network for a running Docker container?

I would like to start a Docker container normally, run it, install some things into it, and then I would like to disable the network, to run some more commands in it, but they should not have access to the network. How can I do that for a running container?
I use docker-py and I know I can use network_disabled to disable networking for the whole container. But I am not sure how I can disable the network after the container is already created. Ideally, I would run the container with command sleep infinity, then docker exec some commands in it, then disable networking, then run few more commands using docker exec.
Maybe an option would be docker network disconnect
Description
Disconnect a container from a network
Usage
docker network disconnect [OPTIONS] NETWORK CONTAINER
Example:
Create a container attached to the default bridge network
docker container run --rm -it alpine ping 8.8.8.8
and after a while disconnect it with:
docker network disconnect bridge <container-name>
The standard pattern you should use here is to write a Dockerfile that does whatever software installation you need, and builds an image out of it. This actually fits your immediate need quite nicely, since once you've built the image you can run it without network.
A typical Dockerfile skeleton might look more or less like
FROM ubuntu:18.04
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
thing-to-run-without-network
CMD ["/usr/bin/thing-to-run-without-network"]
And then you'd build and run it as
docker build -t no-net-test .
docker run --rm --net none no-net-test
Generally you should set your image up so that docker run does everything the container needs to do, without needing to docker exec ever (except for hand debugging). You should never install things into a running container: your work will get lost as soon as you docker rm the container, and deleting and restarting your containers is extremely routine.

How to run gui apps like gvim from docker container

To play around with a docker image, I installed docker and ran a sample docker ubuntu image as follows. (I hope I am using terminology correctly, still a docker noob)
docker run -it ubuntu
Because gvim or anyother gui based program was not installed, by default, I did, inside the ubuntu docker container
apt-get update
apt-get install x11-apps vim-gtk
However, on running xclock I get
root#59be2b1afca0:/# xclock
Error: Can't open display: :0
root#59be2b1afca0:/#
On running gvim I get
root#59be2b1afca0:/# gvim
E233: cannot open display
Press ENTER or type command to continue
So why won't gui apps work?
Containers weren't quite designed originally for gui apps, but rather for services, workers, processes, etc.. On the other hand since containerisation is a kernel construct to isolate and dedicate resources in a more managed way which can expose ports or share volumes, and devices etc..
This means you can technically map your screen, audio, webcam devices to a container by using --device /dev/xyz when you run your docker run command:
docker run [--rm [-it]|-d] \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY \
--device /dev/dri \
myimage [cmd]
I actually found an article describing this here - including audio, camera and other device mapping.
http://somatorio.org/en/post/running-gui-apps-with-docker/
Hope this helps a bit!

download and run ubuntu-desktop with gnome support via docker

I am completely new to docker. I have a Redhat 7 desktop with docker installed.
I now want to run a full fledged ubuntu-desktop 18.04 (including its gnome GUI) via docker. How can this be done? I have been googling for instructions/tutorials on where I can download an ubuntu 18.04 docker image (with GUI support) and run it, but surprisingly I cannot find anything. Can someone help me? Thanks.
I have a different situation, where I run docker on a Windows10 platform. I also tried to install Gnome for some Ubuntu image and start a gnome-session from the terminal. I did not manage to do so.
My current solution is to use Mate instead of Gnome. Maybe my steps are helpful for others that just started with docker:
Install Docker Desktop on Windows 10 and start the Docker application
Install vcxsrv and start it with Xlaunch (also see https://dev.to/darksmile92/run-gui-app-in-linux-docker-container-on-windows-host-4kde)
Get the IP of your computer with ipconfig, e.g 192.111.999.9
Open a console with admin rights and start a docker container. Pass some DISPLAY-Information including your IP:
docker run -it -e DISPLAY=192.111.999.9:0.0 --privileged --name=ubuntu ubuntu
You should then see a linux prompt
Update the package-manager and upgrade existing packages:
apt-get update
apt-get upgrade -y
apt-get update
start dbus service to avoid dbus warnings (also see https://georgik.rocks/how-to-start-d-bus-in-docker-container/):
dbus-uuidgen > /var/lib/dbus/machine-id
mkdir -p /var/run/dbus
dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address
install mate (and some themes to avoid theme warning)
apt-get install mate-desktop-environment -y
apt-get ubuntu-mate-themes -y
start a Desktop session with
mate-session
Good luck!
(If you want some more programs, instead of "mate-desktop-environment", you can also use the larger package "ubuntu-mate-desktop". Will take > 10 min to be installed.)
This is an atypical use case for Docker. Docker is normally used to run applications via the command line, or on a server without GUI support. Most operating systems in docker images ship without GUI support.
However, you can enable GUI support with X11. Only with containers that support it though, and not with Ubuntu as far as I can tell. More details on this blog post: https://blog.jessfraz.com/post/docker-containers-on-the-desktop/
For now, just run docker run -it --rm ubuntu:latest bash and you'll launch an Ubuntu 18.04 shell (at the time of this post).

Docker GUI app (xterm window) from VNC host

I've built a very basic docker container to try and proof of concept running an xterm window from inside it.
In it, I have a basic install of RHEL 7.3 and xterm
I build as normal, open xhost xhost + and then run the docker run command like so:
docker run -ti --rm -e DISPLAY=${DISPLAY} -v /tmp/.X11-unix:/tmp.X11-unix xtermDemo /bin/bash
This runs perfectly when my base host is linux. The problem is that most of the developers in my organization run with a Windows/Mac host and log into a VNC session. When running the docker image from the VNC session xterm can’t run.
Any ideas? My only hunch at the moment is that the VNC Xorg isn't being ran natively and that somehow is causing the issue.

Resources