DEV Community

Kay Gosho
Kay Gosho

Posted on

We can virtualize even GUI Text Editor with Docker

Recently, I virtualized almost everything with Docker.

Finally I virtualized my Emacs with GUI because I am using Arch Linux which cannot provide emacs-mozc and fcitx-mozc for package namespace collision.

So I installed Emacs with X11 client in Docker container, then display Emacs screen to Host's X11 server.


  • Host OS:Arch Linux
  • Guest OS:Debian GNU/Linux
  • Docker version: 1.12.1


First of all, write quite simple Dockerfile. Hopefully install some tools like emacs-mozc or cask.

FROM debian:latest

RUN apt-get update
RUN apt-get -y install emacs24

RUN useradd -G sudo -u 1000 --create-home emacs

ENV HOME /home/emacs
WORKDIR /home/emacs

CMD /usr/bin/emacs --reverse
Enter fullscreen mode Exit fullscreen mode

Then run docker build --tag emacs . in the directory with above Dockerfile.

Next, create a launch script and put it to a directory. $PATH must include the directory.


xhost +local:
docker run -it --rm \
       -v /tmp/.X11-unix:/tmp/.X11-unix \
       -v $HOME:/home/emacs/host_home \
       -e DISPLAY=$DISPLAY \
       --user 1000 \

xhost -local:
Enter fullscreen mode Exit fullscreen mode

The above code just do

  • Pass $DISPLAY env var to the container
  • Share $HOME directory for general usage
  • Share /tmp/.X11-unix between host and container to connect X11 socket

Finally launch emacs:


It works!


To check the host and guest interaction let's run dired emacs file explorer.


Yes, $HOME of host is mounted to the container.
In the container these files owner are recognized as Docker executing user(emacs). cause the UID 1000 matches.


  • If HOST UID and GUEST UID does not match, we cannot edit files for permission problem.
  • We cannot use Symbolic link in the container like Docker, LXC. This is sometimes really inconvenient.

This post is a kind of joke to some extent, but I will use emacs-docker actively.


There is /tmp/.XIM-unix directory. If we mount it then possibly we can virtualize XIM functions.

Container is a dream.

Top comments (4)

juanitomint profile image
Juan Ignacio Borda

What about debian-slim ?
Not only i like containers i want them to be small!
Nice article

acro5piano profile image
Kay Gosho

Thank you for your comment!
Yeah smaller container image like debian-slim or alpine should be better as you pointed out.

iridakos profile image
Lazarus Lazaridis

Nice post!

acro5piano profile image
Kay Gosho

Thank you!