Docker WordPress multisite with subdomains

docker wordpress - theimpossiblecode.com

The network setup for a WordPress multisite with subdomains can be scary. Nevertheless this post will demonstrate how easy it is to use docker-compose to create such a configuration. In addition it will run on your single local host, and you can use it for development, testing, or whatever you want. In a few simple steps you’ll have a docker WordPress multisite with subdomains!

Why use a docker WordPress multisite with subdomains?

Using subdomains for a web site is not everybody’s cup of tea. But if it is, then the network setup overhead is something which you don’t do very often. Letting developers work independently, testing and even just trying it out before publishing a new site needs to be easy. Therefore, I’m going to show you here just how simple it is to add such a setup using docker-compose and the EXPOSE SERVICE feature from a previous post.

It is that simple

  • First of all setup your local Linux as explained in EXPOSE SERVICE.
  • Then create a new directory for your docker-compose.yml:
ubuntu@docker:~/docker$ mkdir wordpress_multisite
ubuntu@docker:~/docker$ cd wordpress_multisite
ubuntu@docker:~/docker/wordpress_multisite$ 
  • Now put this in a new file named docker-compose.yml (based on this):
version: '3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     hostname: dockerwp
     labels:
       com.theimpossiblecode.expose.domain: "mycompanysite.com"
       com.theimpossiblecode.expose.subdomainHosts: "support shop jobs"
     depends_on:
       - db
     image: wordpress:latest
     volumes:
       - wp_data:/var/www/html
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
volumes:
    db_data:
    wp_data:

This gives you a main site at mycompanysite.com, with these subdomains (for which you’ll add sites):

support.mycompanysite.com

shop.mycompanysite.com

jobs.mycompanysite.com.

  • And last, all that is left is to start it up:
ubuntu@docker:~/docker/wordpress_multisite$ docker-compose up -d
Creating wordpressmultisite_db_1 ... 
Creating wordpressmultisite_db_1 ... done
Creating wordpressmultisite_wordpress_1 ... 
Creating wordpressmultisite_wordpress_1 ... done

That was all the networking setup!

To access your /var/www/html files simply use docker exec:

ubuntu@docker:~/docker/wordpress_multisite$ docker exec -it wordpressmultisite_wordpress_1 bash
root@dockerwp:/var/www/html#

To start your multisite setup, open your browser at http://mycompanysite.com, start the regular setup for the main site, and then follow these instructions to configure it as a multisite and add your subdomain sites.

Note – in the process you might get a “Warning! Wildcard DNS may not be configured correctly!”ignore this message and continue.

Hope you find this useful,
Sagi.

Sagi Zeevi

A software developer brain surgeon … if software only had a brain.
An electronics hobbyist heart surgeon … if electronics only had a heart.

You may also like...

Leave a Reply

Scroll Up