Emacs editing in an October CMS Docker container

Create an October CMS Docker image with support for 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.
 2#
 3# Twitter: @maridonkers | Google+: +MariDonkers | GitHub: maridonkers.
 4#
 5
 6FROM debian
 7
 8RUN sed -i "s#\smain\s*\$# main contrib non-free#" /etc/apt/sources.list
 9
10RUN apt-get update && apt-get install -yq procps sudo git-core zip curl gnupg
11RUN apt-get install -yq emacs25 vim silversearcher-ag
12
13# Repository for newer PHP versions (Debian Stretch has 7.0 but e.g. phpactor requires >=7.1).
14# https://tecadmin.net/install-php-debian-9-stretch/
15RUN apt-get install -yq ca-certificates apt-transport-https
16RUN curl -sS https://packages.sury.org/php/apt.gpg | apt-key add -
17RUN echo "deb https://packages.sury.org/php/ stretch main" >> /etc/apt/sources.list.d/php.list
18RUN 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
19
20ENV COMPOSER_ALLOW_SUPERUSER=1
21RUN mkdir -p /opt/php
22RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/opt/php --filename=composer
23RUN ln -s /opt/php/composer /usr/local/bin/composer
24
25WORKDIR /opt/php
26RUN curl -LO https://github.com/phpstan/phpstan/releases/download/0.10.5/phpstan.phar
27RUN chmod +x phpstan.phar
28RUN ln -s /opt/php/phpstan.phar /usr/local/bin/phpstan
29
30WORKDIR /opt/php
31RUN curl -LO https://psysh.org/psysh
32RUN chmod +x psysh
33RUN ln -s /opt/php/psysh /usr/local/bin/psysh
34
35RUN sed -i "s#^\(www-data:.*:\)/usr/sbin/nologin#\1/bin/bash#" /etc/passwd
36RUN echo "www-data ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
37WORKDIR /var/www
38
39ENV DISPLAY=:0
40ENTRYPOINT ["/bin/bash"]

The Docker compose file

 1# Basic PHP container for October CMS PHP editing with Emacs.
 2#
 3# Twitter: @maridonkers | Google+: +MariDonkers | GitHub: maridonkers.
 4#
 5# Docker image: https://hub.docker.com/r/aspendigital/octobercms/
 6#
 7# BEWARE: firewall must allow docker interface for 3306 (otherwise connection errors).
 8#       : use http://127.0.0.1:8081 to access October CMS GUI if localhost doesn't work;
 9#       : To seed database use docker-compose exec web php artisan october:up
10
11version: '2'
12
13services:
14  db:
15    image: mysql:5.7
16    restart: unless-stopped
17    volumes:
18      - db:/var/lib/mysql
19    environment:
20      MYSQL_ROOT_PASSWORD: root
21      MYSQL_DATABASE: octobercms
22    networks:
23      - back
24    ports:
25      - 3306:3306
26
27  phpmyadmin:
28     depends_on:
29       - db
30     image: phpmyadmin/phpmyadmin
31     restart: unless-stopped
32     environment:
33       MYSQL_ROOT_PASSWORD: root
34       MYSQL_USER: root
35       MYSQL_PASSWORD: root
36       PMA_USER: root
37       PMA_PASSWORD: root
38       PMA_ARBITRARY: 1
39     networks:
40       - back
41     ports:
42       - 8091:80
43
44  octobercms:
45    depends_on:
46       - db
47    image: aspendigital/octobercms
48    restart: unless-stopped
49    volumes:
50       - www:/var/www
51    environment:
52       DB_TYPE: mysql
53       DB_HOST: db #DB_HOST should match the service name of the database container
54       DB_DATABASE: octobercms
55       DB_USERNAME: root
56       DB_PASSWORD: root
57    networks:
58      - back
59    ports:
60      - 8081:80
61
62  octobercms-development:
63    depends_on:
64      - octobercms
65    image: octobercms-development
66    build: .
67    volumes:
68      - www:/var/www
69    environment:
70       DISPLAY:
71    network_mode: host
72    stdin_open: true
73    tty: true
74
75networks:
76  back:
77
78volumes:
79  db:
80  www:

Compose up

To build images and bring them up.

1$ docker-compose up -d
2Creating network "octobercms_back" with the default driver
3Creating volume "octobercms_www" with default driver
4Creating volume "octobercms_db" with default driver
5Creating octobercms_db_1
6Creating octobercms_octobercms_1
7Creating octobercms_phpmyadmin_1
8Creating octobercms_octobercms-development_1

Initialize and seed database:

 1$ docker-compose exec octobercms php artisan october:up
 2Migrating application and plugins...
 3Migration table created
 4System
 5 - Migrating: 2013_10_01_000001_Db_Deferred_Bindings
 6 - Migrated:  2013_10_01_000001_Db_Deferred_Bindings
 7 - Migrating: 2013_10_01_000002_Db_System_Files
 8 - Migrated:  2013_10_01_000002_Db_System_Files
 9 - Migrating: 2013_10_01_000003_Db_System_Plugin_Versions
10 - Migrated:  2013_10_01_000003_Db_System_Plugin_Versions
11 - Migrating: 2013_10_01_000004_Db_System_Plugin_History
12 - Migrated:  2013_10_01_000004_Db_System_Plugin_History
13 - Migrating: 2013_10_01_000005_Db_System_Settings
14 - Migrated:  2013_10_01_000005_Db_System_Settings
15 - Migrating: 2013_10_01_000006_Db_System_Parameters
16 - Migrated:  2013_10_01_000006_Db_System_Parameters
17 - Migrating: 2013_10_01_000007_Db_System_Add_Disabled_Flag
18 - Migrated:  2013_10_01_000007_Db_System_Add_Disabled_Flag
19 - Migrating: 2013_10_01_000008_Db_System_Mail_Templates
20 - Migrated:  2013_10_01_000008_Db_System_Mail_Templates
21 - Migrating: 2013_10_01_000009_Db_System_Mail_Layouts
22 - Migrated:  2013_10_01_000009_Db_System_Mail_Layouts
23 - Migrating: 2014_10_01_000010_Db_Jobs
24 - Migrated:  2014_10_01_000010_Db_Jobs
25 - Migrating: 2014_10_01_000011_Db_System_Event_Logs
26 - Migrated:  2014_10_01_000011_Db_System_Event_Logs
27 - Migrating: 2014_10_01_000012_Db_System_Request_Logs
28 - Migrated:  2014_10_01_000012_Db_System_Request_Logs
29 - Migrating: 2014_10_01_000013_Db_System_Sessions
30 - Migrated:  2014_10_01_000013_Db_System_Sessions
31 - Migrating: 2015_10_01_000014_Db_System_Mail_Layout_Rename
32 - Migrated:  2015_10_01_000014_Db_System_Mail_Layout_Rename
33 - Migrating: 2015_10_01_000015_Db_System_Add_Frozen_Flag
34 - Migrated:  2015_10_01_000015_Db_System_Add_Frozen_Flag
35 - Migrating: 2015_10_01_000016_Db_Cache
36 - Migrated:  2015_10_01_000016_Db_Cache
37 - Migrating: 2015_10_01_000017_Db_System_Revisions
38 - Migrated:  2015_10_01_000017_Db_System_Revisions
39 - Migrating: 2015_10_01_000018_Db_FailedJobs
40 - Migrated:  2015_10_01_000018_Db_FailedJobs
41 - Migrating: 2016_10_01_000019_Db_System_Plugin_History_Detail_Text
42 - Migrated:  2016_10_01_000019_Db_System_Plugin_History_Detail_Text
43 - Migrating: 2016_10_01_000020_Db_System_Timestamp_Fix
44 - Migrated:  2016_10_01_000020_Db_System_Timestamp_Fix
45 - Migrating: 2017_08_04_121309_Db_Deferred_Bindings_Add_Index_Session
46 - Migrated:  2017_08_04_121309_Db_Deferred_Bindings_Add_Index_Session
47 - Migrating: 2017_10_01_000021_Db_System_Sessions_Update
48 - Migrated:  2017_10_01_000021_Db_System_Sessions_Update
49 - Migrating: 2017_10_01_000022_Db_Jobs_FailedJobs_Update
50 - Migrated:  2017_10_01_000022_Db_Jobs_FailedJobs_Update
51 - Migrating: 2017_10_01_000023_Db_System_Mail_Partials
52 - Migrated:  2017_10_01_000023_Db_System_Mail_Partials
53 - Migrating: 2017_10_23_000024_Db_System_Mail_Layouts_Add_Options_Field
54 - Migrated:  2017_10_23_000024_Db_System_Mail_Layouts_Add_Options_Field
55Backend
56 - Migrating: 2013_10_01_000001_Db_Backend_Users
57 - Migrated:  2013_10_01_000001_Db_Backend_Users
58 - Migrating: 2013_10_01_000002_Db_Backend_User_Groups
59 - Migrated:  2013_10_01_000002_Db_Backend_User_Groups
60 - Migrating: 2013_10_01_000003_Db_Backend_Users_Groups
61 - Migrated:  2013_10_01_000003_Db_Backend_Users_Groups
62 - Migrating: 2013_10_01_000004_Db_Backend_User_Throttle
63 - Migrated:  2013_10_01_000004_Db_Backend_User_Throttle
64 - Migrating: 2014_01_04_000005_Db_Backend_User_Preferences
65 - Migrated:  2014_01_04_000005_Db_Backend_User_Preferences
66 - Migrating: 2014_10_01_000006_Db_Backend_Access_Log
67 - Migrated:  2014_10_01_000006_Db_Backend_Access_Log
68 - Migrating: 2014_10_01_000007_Db_Backend_Add_Description_Field
69 - Migrated:  2014_10_01_000007_Db_Backend_Add_Description_Field
70 - Migrating: 2015_10_01_000008_Db_Backend_Add_Superuser_Flag
71 - Migrated:  2015_10_01_000008_Db_Backend_Add_Superuser_Flag
72 - Migrating: 2016_10_01_000009_Db_Backend_Timestamp_Fix
73 - Migrated:  2016_10_01_000009_Db_Backend_Timestamp_Fix
74 - Migrating: 2017_10_01_000010_Db_Backend_User_Roles
75 - Migrated:  2017_10_01_000010_Db_Backend_User_Roles
76Cms
77 - Migrating: 2014_10_01_000001_Db_Cms_Theme_Data
78 - Migrated:  2014_10_01_000001_Db_Cms_Theme_Data
79 - Migrating: 2016_10_01_000002_Db_Cms_Timestamp_Fix
80 - Migrated:  2016_10_01_000002_Db_Cms_Timestamp_Fix
81 - Migrating: 2017_10_01_000003_Db_Cms_Theme_Logs
82 - Migrated:  2017_10_01_000003_Db_Cms_Theme_Logs
83October.Demo
84- v1.0.1:  First version of Demo
85October.Drivers
86- v1.0.1:  First version of Drivers
87- v1.0.2:  Update Guzzle library to version 5.0
88- v1.1.0:  Update AWS library to version 3.0
89- v1.1.1:  Update Guzzle library to version 6.0
90- v1.1.2:  Update Guzzle library to version 6.3
91Seeded System 
92Seeded Backend

Visit http://localhost:8081 for the October CMS front end and http://localhost:8081/backend for the backend. Visit http://localhost:8091 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 octobercms_octobercms-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
 5
 6Warning: due to a long standing Gtk+ bug
 7http://bugzilla.gnome.org/show_bug.cgi?id=85715
 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.
24
25www-data$ emacsclient -nc html/server.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/server.php commands.

Emacs running

Posts in this Series