Emacs editing in a Wordpress Docker container

Create a Wordpress Docker image with Emacs editing set up (HTML, CSS, PHP files). With phpMyAdmin support. Under Debian Linux of course.

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

Define the image via a Dockerfile

The Dockerfile:

 1# Basic PHP container for PHP editing with Emacs.
 3# Twitter: @maridonkers | Google+: +MariDonkers | GitHub: maridonkers.
 5# Use a .gitignore, e.g. https://salferrarello.com/wordpress-gitignore/
 7FROM debian
 9RUN sed -i "s#\smain\s*\$# main contrib non-free#" /etc/apt/sources.list
11RUN apt-get update && apt-get install -yq procps sudo git-core zip curl gnupg
12RUN apt-get install -yq emacs25 vim silversearcher-ag
14# Repository for newer PHP versions (Debian Stretch has 7.0 but e.g. phpactor requires >=7.1).
15# https://tecadmin.net/install-php-debian-9-stretch/
16RUN apt-get install -yq ca-certificates apt-transport-https
17RUN curl -sS https://packages.sury.org/php/apt.gpg | apt-key add -
18RUN echo "deb https://packages.sury.org/php/ stretch main" >> /etc/apt/sources.list.d/php.list
19RUN apt-get update && apt-get install -yq php7.2-cli php7.2-common php7.2-curl php7.2-mbstring php7.2-mysql php7.2-xml
22RUN mkdir -p /opt/php
23RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/opt/php --filename=composer
24RUN ln -s /opt/php/composer /usr/local/bin/composer
26WORKDIR /opt/php
27RUN curl -LO https://github.com/phpstan/phpstan/releases/download/0.10.5/phpstan.phar
28RUN chmod +x phpstan.phar
29RUN ln -s /opt/php/phpstan.phar /usr/local/bin/phpstan
31WORKDIR /opt/php
32RUN curl -LO https://psysh.org/psysh
33RUN chmod +x psysh
34RUN ln -s /opt/php/psysh /usr/local/bin/psysh
36RUN sed -i "s#^\(www-data:.*:\)/usr/sbin/nologin#\1/bin/bash#" /etc/passwd
37RUN echo "www-data ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
38WORKDIR /var/www
41ENTRYPOINT ["/bin/bash"]

The Docker compose file

 1# Basic PHP container for Wordpress PHP editing with Emacs.
 3# Twitter: @maridonkers | Google+: +MariDonkers | GitHub: maridonkers.
 5# BEWARE: firewall must allow docker interface for 3306 (otherwise connection errors);
 6#       : use to access Wordpress GUI if localhost doesn't work.
 8version: '2'
10  db:
11     image: mysql:5.7
12     volumes:
13       - db:/var/lib/mysql
14     restart: unless-stopped
15     environment:
16       MYSQL_ROOT_PASSWORD: somewordpress
17       MYSQL_DATABASE: wordpress
18       MYSQL_USER: wordpress
19       MYSQL_PASSWORD: wordpress
20     networks:
21       - back
23  phpmyadmin:
24     depends_on:
25       - db
26     image: phpmyadmin/phpmyadmin
27     restart: unless-stopped
28     environment:
29       MYSQL_ROOT_PASSWORD: somewordpress
30       MYSQL_USER: wordpress
31       MYSQL_PASSWORD: wordpress
32       PMA_USER: wordpress
33       PMA_PASSWORD: wordpress
34       PMA_ARBITRARY: 1
35     networks:
36       - back
37     ports:
38       - 8090:80
40  wordpress:
41    depends_on:
42      - db
43    image: wordpress:latest
44    restart: unless-stopped
45    volumes:
46       - www:/var/www
47       - html:/var/www/html
48    environment:
49       WORDPRESS_DB_HOST: db:3306
50       WORDPRESS_DB_USER: wordpress
51       WORDPRESS_DB_PASSWORD: wordpress
52    networks:
53       - back
54    ports:
55       - 8080:80
57  development:
58    depends_on:
59      - wordpress
60    # restart: always
61    image: wordpress-development
62    build: .
63    environment:
64       DISPLAY:
65    volumes:
66       - www:/var/www
67       - html:/var/www/html
68    network_mode: host
69    stdin_open: true
70    tty: true
73  back:
76  db:
77  www:
78  html:

Compose up

To build images and bring them up.

1$ docker-compose up -d
2Creating network "wordpress_back" with the default driver
3Creating volume "wordpress_www" with default driver
4Creating volume "wordpress_html" with default driver
5Creating volume "wordpress_db" with default driver
6Creating wordpress_db_1
7Creating wordpress_phpmyadmin_1
8Creating wordpress_wordpress_1
9Creating wordpress_development_1

Visit for the Wordpress front end and for the backend. Visit http://localhost:8090 for the phpMyAdmin interface.

Connect to development image

First enable access for X-Windows:

1xhost +LOCAL:

Attach to a bash shell in the container and set up Emacs.

1$ docker attach wordpress_wordpress-development_1

From the bash shell in the container:

 1# chown www-data /var/www
 2# su - www-data
 3www-data$ git clone https://github.com/maridonkers/emacs-config.git /var/www/.emacs.d
 4www-data$ emacs --daemon
 6Warning: due to a long standing Gtk+ bug
 8Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.
 9Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.
10Loading 00debian-vars...
11Loading 00debian-vars...done
12Loading /etc/emacs/site-start.d/50autoconf.el (source)...
13Loading /etc/emacs/site-start.d/50autoconf.el (source)...done
14Loading /var/www/.emacs.d/loader.el (source)...
15Lets install some packages
16running packages-install
17[yas] Prepared just-in-time loading of snippets (but no snippets found).
18[yas] Prepared just-in-time loading of snippets successfully.
19Loading /var/www/.emacs.d/loader.el (source)...done
20Loaded /var/www/.emacs.d/loader.el
21Wrote /var/www/.emacs.d/.emacs.desktop.lock
22Desktop: 2 frames, 19 buffers restored.
23Starting Emacs daemon.
25www-data$ emacsclient -nc html/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 html/index.php commands.

Emacs running

Posts in this Series