wordpress + sqlite quick start with docker compose
Today I have been trying out the sqlite plugin for wordpress that will reach wp Core on a near future. I did found different instructions out there, but was looking for something I could spin up and down without having to either require an existing running instance, running manual steps or trust non official images, so I ended up writing a docker compose project reference to set the whole thing up. Note the following is for local play testing purposes only.
The repo includes a
db.php file (copied from the plugin
db.copy file), that gets filled up during the plugin activation. Instead of doing that, it is included and already filled in. WordPress also wants a
wp-config.php file present to tell it it has been configured, and the configuration steps require a database connection. I also wanted to skip this step. I also went overboard and ended up running the wordpress alpine with php-fpm image instead of the stock image starting an apache server, so it also includes an
fpm.conf file containing a s[ai]mple configuration to nginx alongside.
The following steps will roughly get you there:
$ git clone https://github.com/eskerda/wp-sqlite-docker-compose $ cd wp-sqlite-docker-compose $ git clone email@example.com:WordPress/sqlite-database-integration.git $ docker compose up -d $ open http://localhost:8080 $ docker compose logs -f
These are the contents of the docker compose file
version: '3.8' services: wordpress: image: wordpress:6.1.1-fpm-alpine volumes: - wordpress:/var/www/html/ - ./wp-config.php:/var/www/html/wp-config.php - ./db.php:/var/www/html/wp-content/db.php - ./sqlite-database-integration:/var/www/html/wp-content/plugins/sqlite-database-integration - ./wp-content:/var/www/html/wp-content nginx: image: nginx:1.7 volumes: - ./fpm.conf:/etc/nginx/conf.d/default.conf - wordpress:/var/www/html ports: - 8080:80 volumes: wordpress:
It defines a volume to hold all the wordpress files so it survives restarts, and also includes a local bind mount to
wp-content for easy playing with the sqlite db. Ideally I would like to bind mount this file directly, but I was getting permission errors and didn’t really want to deal with that pain at the moment.
$ sqlite3 wp-content/database/wordpress.db SQLite version 3.37.0 2021-12-09 01:34:53 Enter ".help" for usage hints. sqlite> .tables wp_commentmeta wp_postmeta wp_termmeta wp_comments wp_posts wp_terms wp_links wp_term_relationships wp_usermeta wp_options wp_term_taxonomy wp_users sqlite> .schema wp_posts CREATE TABLE wp_posts ( ID integer NOT NULL PRIMARY KEY AUTOINCREMENT , post_author integer NOT NULL default '0', post_date text NOT NULL default '0000-00-00 00:00:00', post_date_gmt text NOT NULL default '0000-00-00 00:00:00', post_content text NOT NULL, post_title text NOT NULL, post_excerpt text NOT NULL, post_status text NOT NULL default 'publish', comment_status text NOT NULL default 'open', ping_status text NOT NULL default 'open', post_password text NOT NULL default '', post_name text NOT NULL default '', to_ping text NOT NULL, pinged text NOT NULL, post_modified text NOT NULL default '0000-00-00 00:00:00', post_modified_gmt text NOT NULL default '0000-00-00 00:00:00', post_content_filtered text NOT NULL, post_parent integer NOT NULL default '0', guid text NOT NULL default '', menu_order integer NOT NULL default '0', post_type text NOT NULL default 'post', post_mime_type text NOT NULL default '', comment_count integer NOT NULL default '0' ); CREATE INDEX post_name ON wp_posts(post_name); CREATE INDEX type_status_date ON wp_posts(post_type,post_status,post_date,ID); CREATE INDEX post_parent ON wp_posts(post_parent); CREATE INDEX post_author ON wp_posts(post_author); sqlite>
Overall, this looks promising and will probably update this wordpress instance to something similar soon™.
As a final note, I wanted to just provide a quick docker oneliner without much of the fpm bind mount complexity I added along the way. The following just works as much:
docker run --name wp-sqlite -v $(realpath wp-config.php):/var/www/html/wp-config.php -v $(realpath db.php):/var/www/html/wp-content/db.php -v $(realpath sqlite-database-integration):/var/www/html/wp-content/plugins/sqlite-database-integration -p 8080:80 wordpress
One thought on “wordpress + sqlite quick start with docker compose”
Thanks for this! One thing: this line doesnt work
git clone firstname.lastname@example.org:WordPress/sqlite-database-integration.git it should be
It should be
git clone https://github.com/WordPress/sqlite-database-integration.git