Emacs editing in a Docker4Drupal container

Create a Docker4Drupal image with support for Emacs editing set up (HTML, CSS, PHP files). Drupal4Docker has Portainer support.

My Emacs configuration is used as an example to configure Emacs in the container.

Docker4Drupal

Initially follow instructions at Local environment with Docker4Drupal.

Add GUI support

Add GUI support to the Docker compose file by adding two lines to the volumes under nginx, below the existing line - ./:/var/www/html, as follows:

1volumes:
2 - ./:/var/www/html
3 - /tmp/.X11-unix/:/tmp/.X11-unix/:ro
4 - ~/.Xauthority:/home/wodby/.Xauthority:rw

This is inspired by the following YouTube video: How to Run a Graphical Application from a Container? Yes, I Know IT! Ep 20.

Compose up

To build images and bring them up.

1$ docker-compose up -d --build

Allow for some time to let it settle.

Visit http://drupal.docker.localhost:8000/ for your site. Visit http://portainer.aboveurl/ for the Portainer interface.

Connect to development image

Execute a root bash shell in the container to install required additional packages.

1$ docker exec -u 0 -ti my_drupal8_project_nginx /bin/bash
2
3bash-4.4# 

From the root bash shell in the container:

1bash-4.4# apk add git emacs-x11 the_silver_searcher ttf-dejavu
2...
3
4bash-4.4# exit

Execute a bash shell in the container to set up Emacs.

1$ docker exec -ti my_drupal8_project_nginx /bin/bash
2/var/www/html$ 

From the bash shell in the container:

1/var/www/html$ git clone https://github.com/maridonkers/emacs-config.git ~/.emacs.d
2...
3
4/var/www/html$ export DISPLAY=:0
5
6/var/www/html$ emacs --daemon
7...
8
9/var/www/html$ emacsclient -nc web/index.php

If the emacsclient command doesn't work the first time then restart the Emacs daemon by repeating the emacs --daemon and emacsclient -nc web/index.php commands.

Emacs running

Posts in this Series