September 11, 2019

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:


   volumes:
      - ./:/var/www/html
      - /tmp/.X11-unix/:/tmp/.X11-unix/:ro
      - ~/.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.

$ 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.drupal.docker.localhost:8000/ for the Portainer interface.

Connect to development image

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

$ docker exec -u 0 -ti my_drupal8_project_nginx /bin/bash

bash-4.4# 

From the root bash shell in the container:

bash-4.4# apk add git emacs-x11 the_silver_searcher ttf-dejavu
...

bash-4.4# exit

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

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

From the bash shell in the container:

/var/www/html$ git clone https://github.com/maridonkers/emacs-config.git ~/.emacs.d
...

/var/www/html$ export DISPLAY=:0

/var/www/html$ emacs --daemon
...

/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

Drupal4Docker-Emacs

Tags: Software Drupal PHP IDE Computer CMS Linux Server Web Docker Client GUI Emacs