RSelenium using Docker and Firefox, Browser Not Opening on Mac RSelenium using Docker and Firefox, Browser Not Opening on Mac docker docker

RSelenium using Docker and Firefox, Browser Not Opening on Mac


I think the issue seems to with your expectations to see the browser. You are launching the browser inside a docker container. The docker container doesn't have a UI, the browser is launched inside the container instance and not on your machine which initiates the call

The default selenium/standalone-firefox doesn't allow viewing of the browser. If you need to view the browser then you need to use the selenium/standalone-firefox-debug image. This image hosts VNC at port 5900 of the container. You will run it using below

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

Then you will execute your code and connect to 127.0.0.1:5900 using a VNC Viewer. It will ask for a password which is secret by default.

Then you will see the browser in that VNC

VNC View

The above is the result of running the code you had in question


Here is a Dockerfile which may be useful to you https://github.com/jessfraz/dockerfiles/blob/master/chrome/stable/Dockerfile

inlined here for convenience:

# Run Chrome in a container## docker run -it \#   --net host \ # may as well YOLO#   --cpuset-cpus 0 \ # control the cpu#   --memory 512mb \ # max memory it can use#   -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket#   -e DISPLAY=unix$DISPLAY \#   -v $HOME/Downloads:/home/chrome/Downloads \#   -v $HOME/.config/google-chrome/:/data \ # if you want to save state#   --security-opt seccomp=$HOME/chrome.json \#   --device /dev/snd \ # so we have sound#   --device /dev/dri \#   -v /dev/shm:/dev/shm \#   --name chrome \#   jess/chrome## You will want the custom seccomp profile:#   wget https://raw.githubusercontent.com/jfrazelle/dotfiles/master/etc/docker/seccomp/chrome.json -O ~/chrome.json# Base docker imageFROM debian:sidLABEL maintainer "Jessie Frazelle <jess@linux.com>"ADD https://dl.google.com/linux/direct/google-talkplugin_current_amd64.deb /src/google-talkplugin_current_amd64.deb# Install ChromeRUN apt-get update && apt-get install -y \    libcanberra-gtk* \    apt-transport-https \    ca-certificates \    curl \    gnupg \    hicolor-icon-theme \    libgl1-mesa-dri \    libgl1-mesa-glx \    libpango1.0-0 \    libpulse0 \    libv4l-0 \    fonts-symbola \    --no-install-recommends \    && curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \    && echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list \    && apt-get update && apt-get install -y \    google-chrome-stable \    --no-install-recommends \    && dpkg -i '/src/google-talkplugin_current_amd64.deb' \    && apt-get purge --auto-remove -y curl \    && rm -rf /var/lib/apt/lists/* \    && rm -rf /src/*.deb# Add chrome userRUN groupadd -r chrome && useradd -r -g chrome -G audio,video chrome \    && mkdir -p /home/chrome/Downloads && chown -R chrome:chrome /home/chromeCOPY local.conf /etc/fonts/local.conf# Run Chrome as non privileged userUSER chrome# Autorun chromeENTRYPOINT [ "google-chrome" ]CMD [ "--user-data-dir=/data" ]

Additionally, this project https://github.com/sameersbn/docker-browser-box

Inlined Dockerfile for convenience.

FROM sameersbn/ubuntu:14.04.20170123ENV TOR_VERSION=6.5 \    TOR_FINGERPRINT=0x4E2C6E8793298290RUN wget -q -O - "https://dl-ssl.google.com/linux/linux_signing_key.pub" | sudo apt-key add - \ && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \ && mkdir ~/.gnupg \ && gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys ${TOR_FINGERPRINT} \ && gpg --fingerprint ${TOR_FINGERPRINT} | grep -q "Key fingerprint = EF6E 286D DA85 EA2A 4BA7  DE68 4E2C 6E87 9329 8290" \ && apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y xz-utils file locales dbus-x11 pulseaudio dmz-cursor-theme curl \      fonts-dejavu fonts-liberation hicolor-icon-theme \      libcanberra-gtk3-0 libcanberra-gtk-module libcanberra-gtk3-module \      libasound2 libglib2.0 libgtk2.0-0 libdbus-glib-1-2 libxt6 libexif12 \      libgl1-mesa-glx libgl1-mesa-dri libstdc++6 nvidia-346 \      gstreamer-1.0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good \      gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav \      google-chrome-stable chromium-browser firefox \ && update-locale LANG=C.UTF-8 LC_MESSAGES=POSIX \ && mkdir -p /usr/lib/tor-browser \ && wget -O /tmp/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz  https://www.torproject.org/dist/torbrowser/${TOR_VERSION}/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz \ && wget -O /tmp/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz.asc https://www.torproject.org/dist/torbrowser/${TOR_VERSION}/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz.asc \ && gpg /tmp/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz.asc \ && tar -Jvxf /tmp/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz --strip=1 -C /usr/lib/tor-browser \ && ln -sf /usr/lib/tor-browser/Browser/start-tor-browser /usr/bin/tor-browser \ && rm -rf /tmp/tor-browser-linux64-${TOR_VERSION}_en-US.tar.xz \ && rm -rf ~/.gnupg \ && rm -rf /var/lib/apt/lists/*COPY scripts/ /var/cache/browser-box/COPY entrypoint.sh /sbin/entrypoint.shCOPY confs/local.conf /etc/fonts/local.confRUN chmod 755 /sbin/entrypoint.shENTRYPOINT ["/sbin/entrypoint.sh"]