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 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: The above code just do
- Pass
$DISPLAYenv var to the container - Share
$HOMEdirectory for general usage - Share
/tmp/.X11-unixbetween host and container to connect X11 socket
Finally launch emacs:
emacs-docker
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.
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)
What about debian-slim ?
Not only i like containers i want them to be small!
Nice article
Thank you for your comment!
Yeah smaller container image like debian-slim or alpine should be better as you pointed out.
Nice post!
Thank you!