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.

Environment

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

Procedure

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.

#!/bin/bash

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

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:

emacs-docker

It works!

Screenshot_2016-10-07_01-26-59.png

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

Screenshot_2016-10-07_01-30-31.png

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.

Attention

  • 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.

Appendix

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

Container is a dream.

Top comments (4)

Collapse
 
juanitomint profile image
Juan Ignacio Borda

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

Collapse
 
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.

Collapse
 
iridakos profile image
Lazarus Lazaridis

Nice post!

Collapse
 
acro5piano profile image
Kay Gosho

Thank you!