0

I wish to run Pycharm community within Docker on my desktop. I have created a Dockerfile (below) and seen it work fine on Mac.

FROM debian:buster-slim
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
    ca-certificates \
    curl \
    apt-utils \
    dirmngr \
    gnupg \
    libasound2 \
    libdbus-glib-1-2 \
    libgtk-3-0 \
    libxrender1 \
    libx11-xcb-dev \
    libx11-xcb1 \
    libxt6 \
    xz-utils \
    --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

ENV HOME /home/user
RUN useradd --create-home --home-dir $HOME user \
    && chown -R user:user $HOME

ENV LANG C.UTF-8

RUN apt-get update && \
    apt-get install -y python-pip \
      vim \
      wget \
      x11-utils \
      xfonts-base \
      xpra


# install PyCharm
RUN cd / && \
    wget -q http://download.jetbrains.com/python/pycharm-community-2019.1.1.tar.gz && \
    tar xvfz pycharm-community-2019.1.1.tar.gz && \ 
    rm pycharm-community-2019.1.1.tar.gz 

USER user

CMD [ "/pycharm-community-2019.1.1/bin/pycharm.sh"]

However when I try to run this on Ubuntu I get X11 errors from the Pycharm code:

Start Failed: Failed to initialize graphics environment

java.awt.AWTError: Can't connect to X11 window server using ':1' as the value of the DISPLAY variable. at java.desktop/sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)

The command to invoke the container is:

docker run -it --rm    -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=${DISPLAY} <<image_id>>

I have tried many variations on the DISPLAY var (eg unix$DISPLAY), but none have worked.

Update:

I ran:

docker run -it --rm    -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=${DISPLAY} --entrypoint /bin/sh <<image_id>>

to get access into the container, and then ran:

$ ls -l /tmp
total 0

I am confused - I thought the X11 socket residing in my host machine would have been bound to the same location in the container. Is this a red-herring?

Mazerunner72
  • 613
  • 2
  • 6
  • 16
  • From that thread : https://stackoverflow.com/questions/16296753/can-you-run-gui-applications-in-a-docker-container : user who started `docker` should have access to `xhost`. Try to run `xhost +local:docker` before starting your container (however, I'm not sure this is the recommended way, but it could help you though). – norbjd Apr 22 '19 at 08:48
  • Thanks I have tried your suggestion and also `xhost +`. Still getting the exact same error. – Mazerunner72 Apr 22 '19 at 10:49
  • Also, `.X11-unix` is an hidden file, you should run `ls -al /tmp` to see it in your container. – norbjd Apr 23 '19 at 08:35

0 Answers0