Reputation: 21
Im trying to use docker to contain my app and forward x11 to spawn Chrome with chromedriver. I could make the browser spawn, but its spawn all blank. Also the context menu its blank. It closes without crashing.
Introductory information: (CAN BE SKIPPED)
I have an app (django+postgresql+supervisor+uwsgi+celery+redis+nginx+selenium) that spawn Chrome/Chromium browsers via Chromedriver with Selenium, opening them in diferent pre-loaded User Data Directories (with pre-loaded sessions and logins) and do some automated stuff in diferents sites.
Everything works smooth and clear in my computer.
Some co-workers ask me to install them my app. I told them it would only work on Linux, since i develop in Linux and im not sure if everything would work same in Windows.
After 1 of them installed Ubuntu, i tried to install everything with my source code, using my private git repo for sharing/updating, and it was extremelly painfull.
First, i had troubles installing the right Python Version, after that, supervisor was not working as i expected. Every step presented diferent troubles, and the app itselft presents some bugs that i dont have in my own environment.
The Trouble itself: (CAN START READING HERE)
So, after a lot of reading, i thought Docker would be fit great, even if its not designed to open desktops apps. A single X11 forward could fix the issue.
I went directly with a Docker-compose file (to speed up the parallel processes setup). This is actually my first time using docker, and its feels really easy. I made to make a Dockerfile and a docker-compose file that setups everything (right python version, chrome/chromedrivers and its dependencies) and everything -excepts Chrome- works great.
After doing some digging and testing with the X11 redirect, i could make my application Launch Chrome and spawn the Chrome windows in my host computer, but the window itselfs its blank. Even if do right click, the opening context menu its all blank.
I ran xhost +local:root
on my host computer but that wont fix the issue.
I'vea read here http://wiki.ros.org/docker/Tutorials/GUI in the Part 3. The Isolated Way, that i should do something like this
```XSOCK=/tmp/.X11-unix
XAUTH=/tmp/.docker.xauth
touch $XAUTH
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
docker run -it \
--volume=$XSOCK:$XSOCK:rw \
--volume=$XAUTH:$XAUTH:rw \
--env="XAUTHORITY=${XAUTH}" \
--env="DISPLAY" \
-user="myNewUserName" \
osrf/ros:indigo-desktop-full \
rqt```
But im not sure how should i do the xauth list stuff inside the docker-compose file (or where should i?). Im actually not 100% sure that my issue is inside xauth.
Here is my docker file: I choose Python 3.7.4-slim-strech since it: * Provides me the right python version * Debian can install chromium and chromedriver from its repositories (chromium version 73) * Its the most easiest setup that i've found for my needs
FROM python:3.7.4-slim-stretch
RUN apt-get update && apt-get install -y chromium chromedriver build-essential
ENV PYTHONUNBUFFERED 1
# My Actual System Username, i've also tested with other username and i have the same issue
ENV USERNAME "gabriel"
# These UID and GID match mines
RUN export uid=1000 gid=1000 && \
addgroup \
--system \
--gid ${gid} \
${USERNAME} && \
adduser \
--system \
--uid ${uid} \
--shell /bin/bash \
--gid ${gid} \
${USERNAME} && \
usermod -aG sudo ${USERNAME} && \
passwd -d ${USERNAME}
RUN mkdir /app && \
mkdir /config && \
mkdir -p /var/www/static
ADD ./config /config
RUN pip install -r /config/requirements.pip
RUN chown -R ${uid}:${gid} /app && \
chown -R ${uid}:${gid} /config && \
chown -R ${uid}:${gid} /var/www && \
chmod +x /config/application_launch.sh
USER ${USERNAME}
ENV HOME /home/${USERNAME}
WORKDIR /app
ADD ./src /app
And here is my docker compose file:
services:
db:
image: postgres
container_name: ps01
supervisor:
build: .
command: supervisord -c /config/supervisord.conf
volumes:
- ./src:/app
- ./src/static:/var/www/static
- /tmp/.X11-unix:/tmp/.X11-unix:rw
ports:
- "9001:9001"
expose:
- "8000"
depends_on:
- db
extra_hosts:
- "yangoo.network:10.68.0.1"
container_name: su01
environment:
- DISPLAY
- UID
- QT_X11_NO-MITSHM=1
nginx:
image: nginx
container_name: wb01
ports:
- "80:80"
volumes:
- ./src:/app
- ./config/nginx:/etc/nginx/conf.d
- ./src/static:/var/www/static
depends_on:
- supervisor
links:
- supervisor
EDIT:
Upgrading my distro to popos 19.04 fixed the blank screen issue. Also i could make it work in a Virtual Machine with a newer linux distro. The problem appear to be present only in older distros.
Upvotes: 2
Views: 2690
Reputation: 347
There is a Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1048186
According to the comments, adding ipc: host
to your supervisor config in docker-compose will work:
supervisor:
build: .
command: supervisord -c /config/supervisord.conf
volumes:
- ./src:/app
- ./src/static:/var/www/static
- /tmp/.X11-unix:/tmp/.X11-unix:rw
ports:
- "9001:9001"
expose:
- "8000"
depends_on:
- db
extra_hosts:
- "yangoo.network:10.68.0.1"
container_name: su01
environment:
- DISPLAY
- UID
- QT_X11_NO-MITSHM=1
ipc: host
Upvotes: 2