Mounting the download file using docker-compose is not working in Zalenium - zalenium

Using below command in .yml file
volumes:
- /your/local/folder:/tmp/node/home/seluser/Downloads
- /tmp/videos:/home/seluser/videos
- /usr/bin/docker:/usr/bin/docker
but it doesn't mount the downloads folder
when i ran the below command
docker run --rm -ti --name zalenium -p 4444:4444 -v /var/run/docker.sock:/var/run/docker.sock \ -v /tmp/videos:/home/seluser/videos -v /your/local/folder:/tmp/node/home/seluser/Downloads --privileged dosel/zalenium start its working fine
How can i make it work using .yml/docker-compose file

Related

Redirecting aws cli v2 to file adds extra control characters

If I run the following command:
docker run -v "$PWD/aws":/root/.aws --rm -it amazon/aws-cli wafv2 list-ip-sets --profile dev --scope=CLOUDFRONT --region=us-east-1 --color off
I get the following output:
{
"IPSets": []
}
If I run the following command:
docker run -v "$PWD/aws":/root/.aws --rm -it amazon/aws-cli wafv2 list-ip-sets --profile dev --scope=CLOUDFRONT --region=us-east-1 --color off > test.txt
I get the following in test.txt:
[?1h=
{[m
"IPSets": [][m
}[m
[K[?1l>
I think these are xterm control codes or something - in any case, how do I get the contents of test.txt to match what is output to the terminal? I am on a Mac but my solution needs to work on Mac and Linux.
Apparently that -it parameter being passed to Docker was the problem. Passing just just -i made it work.

Running docker as sibling

I am trying to run a container (hello-world) as a sibling from another container (dev).
But, container script is not able to access "Docker". I am getting
Docker not found error
Here is what I am doing: dev Dockerfile downloads the docker image Like
ENV DOCKER_VERSION=19.03.8
RUN curl -sfL -o docker.tgz
"https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz" && \
tar -xzf docker.tgz docker/docker --strip=1 --directory /usr/local/bin && \
rm docker.tgz
RUN ["chmod","+x","./script.sh"]
ENTRYPOINT ["sh","./script.sh"]
script.sh is:
#!/bin/bash
docker run hello-world
Docker Build command:
docker build -t dev .
Docker run command:
docker run -v /var/run/docker.sock:/var/run/docker.sock <container_image>

chowning the host's bound `docker.sock` inside container breaks host docker

On a vanilla install of Docker for Mac my docker.sock is owned by my local user:
$ stat -c "%U:%G" /var/run/docker.sock
juliano:staff
Even if I add the user and group on my Dockerfile, when trying to run DinD as me, the mount of the docker.sock is created with root:root.
$ docker run -it --rm \
--volume /var/run/docker.sock:/var/run/docker.sock \
--group-add staff \
--user $(id -u):$(id -g) \
"your-average-container:latest" \
/bin/bash -c 'ls -l /var/run/docker.sock'
srw-rw---- 1 root root 0 Jun 17 07:34 /var/run/docker.sock
Going the other way, running DinD as root, chowning the socket, then running commands breaks the host docker.
$ docker run -it --rm \
--volume /var/run/docker.sock:/var/run/docker.sock \
--group-add staff \
"your-average-container:latest" \
/bin/bash
$ chown juliano:staff /var/run/docker.sock
$ sudo su juliano
$ docker ps
[some valid docker output]
$ exit
$ docker ps
Error response from daemon: Bad response from Docker engine
I've seen people reporting chowning as the way to go, so maybe I'm doing something wrong.
Questions:
Why does the host docker break?
Is there some way to prevent host docker from breaking and still giving my user permission to the socket inside docker?
I believe that when you are mounting the volume the owner UID/GID is set to the same as in the host machine (the --user flag simply allows you to run the command as a specific UID/GID and it doesn't have impact on the permission for mounted volume)
The main question is - why would you need to chown? Can't you just run the commands inside the container as root?

Can't open dashboard

I'm using Windows and installed Zalenium with the .\prepare.bat
Then, when i try o start Zalenium with:
docker run --rm -ti --name zalenium -p 4444:4444
-v /var/run/docker.sock:/var/run/docker.sock
-v /tmp/videos:/home/seluser/videos
--privileged dosel/zalenium start
I get an error on the console:
Copying files for Dashboard...
cp: cannot create regular file '/home/seluser/videos/dashboard.html': No such file or directory
Everything works except the Dashboard.
What am i doing wrong?
I'm using the latest version.
Thank you
Error clearly say that it is trying to look for the file in LINUX like structure "/home/seluser/videos/" which will not be available on windows.
When you start zalenium, It looks for dashboard.html in the mount drive. Without this file dashboard will not be visible.
You should use below command in case of windows.
docker run --rm -ti --name zalenium -p 4444:4444 ^
-v /var/run/docker.sock:/var/run/docker.sock ^
-v /c/Users/your_user_name/temp/videos:/home/seluser/videos ^
--privileged dosel/zalenium start
Zalenium documentation
I'm new to Zalenium but I found out that the run command on the Zalenium Github page does not work on all systems.
Try this command i use and let me know if it works for
*docker run --rm -ti --name zalenium -p 4444:4444 -v /var/run/docker.sock:/var/run/docker.sock --privileged dosel/zalenium start*
docker run -d -ti --name zalenium -p 4445:4444 -v /var/run/docker.sock:/var/run/docker.sock -v /tmp/videos:/home/seluser/videos --restart=always --privileged dosel/zalenium start
worked for me.. dashboard opens on 4445 port

How to run cucumber/selenium tests in Docker?

I am struggling to run my cucumber tests from a Docker image.
Here is my setup:
I use OSX with XQuartz to run an X11 session
I use an Ubuntu 14 Vagrant image for development where I forward my X11 session
I am trying to run a docker image with Firefox that will use my XQuartz session for display
So far, I managed to start Firefox with the following setup:
# Dockerfile
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y firefox
# Replace 1000 with something appropriate ;)
RUN export uid=1000 gid=1000 && \
mkdir -p /home/developer && \
echo "developer:x:${uid}:${gid}:Developer,,,:/home/dev:/bin/bash" >> /etc/passwd && \
echo "developer:x:${uid}:" >> /etc/group && \
echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && \
chmod 0440 /etc/sudoers.d/developer && \
chown ${uid}:${gid} -R /home/developer
USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox
I can start Firefox with --net=host from my Vagrant machine:
docker build -t firefox .
docker run --net=host -ti --rm -e DISPLAY=$DISPLAY -v $HOME/.Xauthority:/home/developer/.Xauthority -v /tmp/.X11-unix:/tmp/.X11-unix:rw firefox:latest
But this is not ideal because I can't link other containers to my machine in the docker-compose.yml file. Ideally, I would like to run my docker machine without --net=host like this:
docker build -t firefox .
docker run -ti --rm -e DISPLAY=$DISPLAY -v $HOME/.Xauthority:/home/developer/.Xauthority -v /tmp/.X11-unix:/tmp/.X11-unix:rw firefox:latest
But I get the following error:
error: XDG_RUNTIME_DIR not set in the environment.
Error: cannot open display: localhost:10.0
Please help :)
You could simply use elgalu/docker-selenium to avoid dealing with what's already solved for you, and maintained:
docker run --rm -ti --net=host --pid=host --name=grid \
-e SELENIUM_HUB_PORT=4444 -e TZ="US/Pacific" \
-v /dev/shm:/dev/shm --privileged elgalu/selenium
If you need advanced features like a dashboard with video recording for example, or live preview, you can use Zalenium and start it with:
curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | bash -s start -i

Resources