2016-10-31 12:13:41 +00:00
#+TITLE : spacemacs-docker distribution
2019-05-02 21:49:30 +00:00
#+TAGS : distribution|layer|spacemacs
2019-05-07 20:05:06 +00:00
* Table of Contents :TOC_5_gh:noexport:
2017-05-22 14:16:12 +00:00
- [[#description ][Description ]]
2017-08-06 01:11:04 +00:00
- [[#features ][Features: ]]
2019-04-21 20:04:25 +00:00
- [[#screenshots ][Screenshots ]]
2017-05-22 14:16:12 +00:00
- [[#how-to-setup ][How to setup ]]
- [[#how-to-use ][How to use ]]
2019-10-13 05:27:17 +00:00
- [[#macos ][macOS ]]
2017-05-22 14:16:12 +00:00
- [[#windows ][Windows ]]
- [[#gnulinux ][GNU/Linux ]]
- [[#with-xpra-on-any-of-the-oses-and-via-web-browser ][With Xpra on any of the OSes and via web-browser ]]
- [[#pros ][Pros ]]
- [[#cons ][Cons ]]
- [[#instruction ][Instruction ]]
- [[#with-xpra-desktop-client ][With Xpra desktop client ]]
- [[#via-web-browser ][Via web-browser ]]
- [[#some-basic-docker-commands-to-get-you-going ][Some basic docker commands to get you going ]]
2016-10-31 12:13:41 +00:00
* Description
2017-03-05 08:38:15 +00:00
Spacemacs distribution that aims to automate dependency installation for
Spacemacs layers and provide well tested Docker based development environment
with GUI support on all major platforms and even [[https://i.imgur.com/wDLDMZN.gif ][your web browser ]].
2017-04-25 15:42:58 +00:00
2017-08-06 01:11:04 +00:00
** Features:
- Automatically get Spacemacs layers dependency installed with [[https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bdistributions/spacemacs-docker/deps-install/README.org ][installer scripts ]]
2019-10-13 05:27:17 +00:00
- Reap the benefit of Emacs and other GNU/Linux tools on Windows or macOS machines
2017-03-05 08:38:15 +00:00
- Use [[https://hub.docker.com/ ][docker hub ]] to auto-build your environment and store full backups for free
- Build once and work with the same development environment everywhere
- Run untrusted/risky code in the tunable sandbox with CPU/network/disk quotas
- Try new tools, experiment and roll back changes when something goes wrong
2019-05-26 20:58:52 +00:00
- Share your setup with others or extend someone else's development environment
2017-03-05 08:38:15 +00:00
- Run multiple Emacs instances on the same machine isolated
2017-04-26 13:50:19 +00:00
- [[https://docs.docker.com/engine/reference/commandline/pause/ ][pause ]] container to free resources temporarily
2019-05-26 20:58:52 +00:00
- [[https://github.com/docker/docker/blob/1.13.x/experimental/checkpoint-restore.md ][Checkpoint & Restore ]] - maybe the fastest way to start a "heavy" environment
2017-03-05 08:38:15 +00:00
- Friendly for networks with low upload speed/quotas.
2019-04-21 19:00:24 +00:00
* Screenshots
[[file:img/MAC_SP.jpg ]]
2019-10-13 05:27:17 +00:00
[[https://i.imgur.com/VcuqReF.jpg ][HD macOS image ]]
2019-04-21 19:00:24 +00:00
[[file:img/LN_SP.jpg ]]
[[https://i.imgur.com/yDok0Q7.jpg ][HD GNU/Linux image ]]
[[file:img/WIN_SP.jpg ]]
[[https://i.imgur.com/WmsnCUo.jpg ][HD Windows image ]]
2017-03-05 08:38:15 +00:00
* How to setup
2019-05-20 10:53:07 +00:00
The idea is to build your own image [[https://docs.docker.com/engine/reference/builder/#from ][FROM ]] the one of provided base images.
Get [[https://docs.docker.com/engine/installation ][docker ]] for the OS of
2017-03-05 08:38:15 +00:00
the machine that will run development environment and then use
2018-09-19 03:54:47 +00:00
[[https://github.com/JAremko/spacemacs-docker-seed ][spacemacs-docker-seed ]] as an example to create [[https://docs.docker.com/docker-hub/builds/ ][automated builds on Docker Hub ]] or
2017-03-05 08:38:15 +00:00
[[https://docs.docker.com/engine/reference/commandline/build/ ][build it locally ]].
* How to use
2019-05-20 10:53:07 +00:00
With one of the methods below replace =spacemacs/develop= with your images.
2017-03-05 08:38:15 +00:00
NOTE: The guide assumes that you want to run Docker and connect to it from
the same machine.
2017-04-25 15:42:58 +00:00
2019-10-13 05:27:17 +00:00
** macOS
2019-05-26 20:58:52 +00:00
Get [[https://www.xquartz.org ][XQuartz ]] and =open -a XQuartz= In the XQuartz preferences go to the "Security"
tab and make sure you've got "Allow connections from network clients" ticked
2018-07-10 10:57:25 +00:00
2017-03-05 08:38:15 +00:00
#+BEGIN_SRC sh
2018-09-19 03:54:47 +00:00
ip=$(ifconfig en0 | grep inet | awk '$1= ="inet" {print $2}')
xhost + $ip
docker run -ti --name spacemacs \
-e DISPLAY=$ip:0 \
-e TZ=<your_time_zone > \
-v <path_to_your_workspace >:/mnt/workspace \
2019-05-20 10:53:07 +00:00
spacemacs/develop
2016-10-31 12:13:41 +00:00
#+END_SRC
2018-07-10 10:57:25 +00:00
2017-03-05 08:38:15 +00:00
[[https://fredrikaverpil.github.io/2016/07/31/docker-for-mac-and-gui-applications ][source ]],
[[https://github.com/chanezon/docker-tips/blob/master/x11/README.md ][another method ]]
2017-04-25 15:42:58 +00:00
2017-03-05 08:38:15 +00:00
** Windows
2018-09-19 03:54:47 +00:00
Get [[https://www.cygwin.com ][Cygwin ]] with =xinit= , =xorg-server= and optionaly [[https://github.com/rprichard/winpty ][winpty ]] (to run Emacs container with =-t= )
#+BEGIN_SRC sh
export DISPLAY=<your-machine-ip >:0.0
startxwin -- -listen tcp &
xhost + <your-machine-ip >
#+END_SRC
2018-07-10 10:57:25 +00:00
2017-03-05 08:38:15 +00:00
#+BEGIN_SRC sh
2018-09-19 03:54:47 +00:00
docker run --name spacemacs \
-e DISPLAY="$DISPLAY" \
-v <path_to_your_workspace >:/mnt/workspace \
2019-05-20 10:53:07 +00:00
spacemacs/develop
2016-10-31 12:13:41 +00:00
#+END_SRC
2018-09-19 03:54:47 +00:00
Or with =-ti= via =winpty=
2018-07-10 10:57:25 +00:00
2017-03-05 08:38:15 +00:00
#+BEGIN_SRC sh
2018-09-19 03:54:47 +00:00
winpty docker run -ti --name spacemacs \
-e DISPLAY="$DISPLAY" \
-v <path_to_your_workspace >:/mnt/workspace \
2019-05-20 10:53:07 +00:00
spacemacs/develop
2017-03-05 08:38:15 +00:00
#+END_SRC
2018-07-10 10:57:25 +00:00
2017-03-05 08:38:15 +00:00
[[http://manomarks.github.io/2015/12/03/docker-gui-windows.html ][source ]]
2019-05-26 20:58:52 +00:00
Also You can use [[https://www.reddit.com/r/emacs/comments/7a63r4/emacs_in_win10linuxdockerxserver_combo/ ][@ninrod 's setup ]]
2017-04-25 15:42:58 +00:00
2017-03-05 08:38:15 +00:00
** GNU/Linux
Make sure that =$DISPLAY= variable is set
2018-07-10 10:57:25 +00:00
2017-03-05 08:38:15 +00:00
#+BEGIN_SRC sh
2018-09-19 03:54:47 +00:00
docker run -ti --name spacemacs \
-e DISPLAY="unix$DISPLAY" \
-e UNAME="spacemacser" \
-e UID="1000" \
-e TZ=<your_time_zone > \
-v /tmp/ .X11-unix:/tmp/ .X11-unix:ro \
-v /etc/localtime:/etc/localtime:ro \
-v /etc/machine-id:/etc/machine-id:ro \
-v /var/run/dbus:/var/run/dbus \
-v <path_to_your_workspace >:/mnt/workspace \
2019-05-20 10:53:07 +00:00
spacemacs/develop
2017-03-05 08:38:15 +00:00
#+END_SRC
2018-07-10 10:57:25 +00:00
2019-05-26 20:58:52 +00:00
=UID= and preferably =UNAME= should match the host's user id. You can set them
2017-03-05 08:38:15 +00:00
in your Dockerfile with [[https://docs.docker.com/engine/reference/builder/#env ][ENV statements ]].
2019-05-26 20:58:52 +00:00
That's it! Now you should see Emacs window.
But if it doesn't work You may need to allow local connection for the user
2018-07-10 10:57:25 +00:00
2017-03-05 08:38:15 +00:00
#+BEGIN_SRC sh
2018-09-19 03:54:47 +00:00
xhost +si:localuser:<UNAME >
2017-03-05 08:38:15 +00:00
#+END_SRC
2018-07-10 10:57:25 +00:00
2019-05-26 20:58:52 +00:00
Or allow local connection from the container's host-name
2018-07-10 10:57:25 +00:00
2017-03-05 08:38:15 +00:00
#+BEGIN_SRC sh
2018-09-19 03:54:47 +00:00
xhost +local:`docker inspect --format='{{ .Config.Hostname }}' spacemacs`
2017-03-05 08:38:15 +00:00
#+END_SRC
2018-07-10 10:57:25 +00:00
2017-03-05 08:38:15 +00:00
[[http://stackoverflow.com/questions/25281992/alternatives-to-ssh-x11-forwarding-for-docker-containers ][source ]]
2017-04-25 15:42:58 +00:00
2017-03-05 08:38:15 +00:00
** With Xpra on any of the OSes and via web-browser
*** Pros
Various documentation copy-edits
Follow up the changes in the previous commit with some minor improvements
to formatting, grammar, spelling, and wording.
* layers/+distributions/spacemacs-docker/README.org: Replace "+" with
"and".
* layers/+email/mu4e/README.org: Use full sentences in the comments in the
mu4e-alert example.
* layers/+intl/japanese/README.org: Use verbatim markers for names of
files, functions, packages, and variables. Capitalize "Linux".
* layers/+os/osx/README.org: Capitalize "Emacs", "Vim", and "Evil".
* layers/+os/osx/config.el (osx-command-as, osx-use-dictionary-app):
* layers/+os/osx/keybindings.el (spacemacs/system-is-mac): Improve
docstrings.
* layers/+readers/dash/README.org: Capitalize "API", "Helm", and "Ivy".
* layers/+spacemacs/spacemacs-defaults/config.el
(delete-by-moving-to-trash): Use full sentences in comment.
* layers/+spacemacs/spacemacs-defaults/funcs.el
(spacemacs/toggle-frame-fullscreen-non-native): Improve docstrings.
2019-10-13 06:03:09 +00:00
- Xpra has a client for GNU/Linux, Windows and macOS and can work via web browser
2017-03-05 08:38:15 +00:00
- Persistent server (you can connect and disconnect without disrupting Emacs)
- Interactive screen sharing [[https://imgur.com/ijdSuX6 ][demo ]]
- Read/write rss/email with Emacs in web-browser (O_O) [[https:/ /imgur.com/wDLDMZN][demo]]
2017-04-25 15:42:58 +00:00
2017-03-05 08:38:15 +00:00
*** Cons
- Lag spikes with some OSes
2017-04-25 15:42:58 +00:00
2017-03-05 08:38:15 +00:00
*** Instruction
2019-05-26 20:58:52 +00:00
It's a good idea to read [[https://github.com/JAremko/docker-x11-bridge ][docker-x11-bridge ]] and [[https://www.xpra.org/trac/ ][Xpra ]] documentations, but
2017-03-05 08:38:15 +00:00
here is a short instruction:
2017-04-25 15:42:58 +00:00
2017-03-05 08:38:15 +00:00
**** With Xpra desktop client
Get [[https://xpra.org/ ][Xpra ]] client for your OS. then
2018-07-10 10:57:25 +00:00
2017-03-05 08:38:15 +00:00
#+BEGIN_SRC sh
2018-09-19 03:54:47 +00:00
docker run -ti --rm --name x11-bridge \
-e MODE="ssh" \
--net=host \
-v ~/.ssh/pub_rsa:/etc/pub-keys/me.pub \
-e DISPLAY=:14 \
jare/x11-bridge
docker run -ti --rm --name spacemacs \
--volumes-from x11-bridge \
-e DISPLAY=:14 \
-e TZ=<your_time_zone > \
2019-05-20 10:53:07 +00:00
spacemacs/develop
2017-03-05 08:38:15 +00:00
#+END_SRC
2018-07-10 10:57:25 +00:00
2017-03-05 08:38:15 +00:00
Now you can connect to it with Xpra desktop client
2018-07-10 10:57:25 +00:00
2017-03-05 08:38:15 +00:00
#+BEGIN_SRC sh
2018-09-19 03:54:47 +00:00
<XPRA EXECUTABLE > attach --encoding=rgb \
--ssh="ssh -o StrictHostKeyChecking=no -p 22" \
ssh:xpra@localhost:14
2017-03-05 08:38:15 +00:00
#+END_SRC
2017-04-25 15:42:58 +00:00
2017-03-05 08:38:15 +00:00
**** Via web-browser
#+BEGIN_SRC sh
2018-09-19 03:54:47 +00:00
docker run -ti --rm --name x11-bridge \
-e MODE="html" \
--net=host \
-e XPRA_PASSWORD=<PASSWORD > \
-e DISPLAY=:14 \
jare/x11-bridge
docker run -ti --rm --name spacemacs \
--volumes-from x11-bridge \
-e TZ=<your_time_zone > \
-e DISPLAY=:14 \
2019-05-20 10:53:07 +00:00
spacemacs/develop
2017-03-05 08:38:15 +00:00
#+END_SRC
2018-07-10 10:57:25 +00:00
2018-09-19 03:54:47 +00:00
Now visit [[http://localhost:10000/index.html?encoding=png&password ]] =<PASSWORD >
2016-10-31 12:13:41 +00:00
2017-03-05 08:38:15 +00:00
* Some basic docker commands to get you going
- =docker rm -f spacemacs= - remove =spacemacs= container
- =docker restart spacemacs= - restart =spacemacs= container
2019-05-20 10:53:07 +00:00
- =docker rmi -f spacemacs/develop= - remove =spacemacs/develop= image
- =docker pull spacemacs/develop= - get newer =spacemacs/develop= version
2017-03-05 08:38:15 +00:00
- =docker images -a= - list all images
- =docker ps -a= - list all containers
2019-05-20 10:53:07 +00:00
- =docker run ... spacemacs/develop= - run default cmd
- =docker run -ti ... spacemacs/develop /bin/bash= - start bash
2017-12-31 16:04:09 +00:00
- =docker run --network=host ...= - less overhead and no need to map ports
2017-03-05 08:38:15 +00:00
- =docker exec spacemacs /usr/bin/emacs= - start =/usr/bin/emacs=
2018-09-19 03:54:47 +00:00
2017-03-05 08:38:15 +00:00
With the running =spacemacs= container
2019-05-26 20:58:52 +00:00
- =docker logs spacemacs= - print =spacemacs= container's logs
2017-03-05 08:38:15 +00:00
- =docker cp <from_local_path> spacemacs:/<to_my_spacemacs_container_path>=
- =docker cp spacemacs:/<from_my_spacemacs_container_path> <to_local_path>=
2018-09-19 03:54:47 +00:00
- Manage data in containers with [[https://docs.docker.com/engine/tutorials/dockervolumes/ ][Docker volumes ]]. Example
- =docker volume create --name my-ws=
2019-05-20 10:53:07 +00:00
- =docker run ... -v my-ws:/mnt/workspace ... spacemacs/develop=
2018-09-19 03:54:47 +00:00
- =docker run ... -v my-ws:/home/developer/workspace ... jare/vim-bundle=