Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
133 lines (84 sloc) 3.8 KB

Docker WordPress Scripts

Docker WordPress Scripts

npm version

DWS is a small set of scripts to manage WordPress containers in Docker. It uses an nginx-proxy for *.localhost domains to avoid manual port assignment.

This is work in progress and unstable!

This is somewhat of a personal project but it solves a fairly common problem so I'm sharing it for anyone to use and adapt. Follow @dbushell for updates and feedback.

Requirements

  • Docker must be installed and running on your machine.
  • Port 80 must be unbound for the proxy server to work.

Install

Run npm init if you don't have a package.json.

Install docker-wordpress-scripts to the project repository:

npm install docker-wordpress-scripts --save

Or use the --global flag to use dws commands anywhere without npx.

Usage

Usage: dws <command> [options]

Commands:
  dws up [proxy]    spin up a new project
  dws stop          stop running containers
  dws start         start existing containers
  dws url           output the *.localhost URL
  dws down [proxy]  stop and remove existing containers
  dws eject         replace DWS dependency with config files

Options:
  --help, -h     Show help
  --version, -v  Show version number

up

npx dws up

DWS will spin up new Docker containers and install WordPress. You'll be asked a few configuration values.

Once successful you'll see:

🐹 Success: WordPress is up and running!
➜ http://wordpress.localhost

The wp-content directory is mounted to wordpress in the project repository. The entire database is mounted to _database (advisable to add to .gitignore).

phpMyAdmin is also set up on the pma subdomain.

Use dws up --proxy to spin up the NGINX proxy. This happens automatically when a project is set up.

stop

npx dws stop

Stop all running containers for the project.

start

npx dws start

Start all existing containers for the project.

url

npx dws url

Output the *.localhost URL for the project.

down

npx dws down

Stop and remove all containers for the project leaving no trace in Docker. The database and WordPress content directories will persist in the project repository. Unless they are deleted the init command can restore the project.

Use dws down --proxy to stop and remove the NGINX proxy.

eject

npx dws eject

Remove the DWS dependency. There is no going back! This adds a copy of docker-compose.yml and other config files to the project repository. You can continue by using docker-compose in the terminal.

The hostname & port for WordPress and phpMyAdmin moves to respectively:

localhost:8080
localhost:8081

Using the NGINX Proxy

If you want to set up a reverse proxy without the help of DWS take a look at the compose files in this directory and nginx-proxy by Jason Wilder.

The proxy set up by DWS is not exclusive and can be used for other projects. Use the external Docker network dws_nginx with VIRTUAL_HOST and VIRTUAL_PORT environment options for the service.

Portainer

An instance of Portainer is also created behind the NGINX proxy. To configure visit:

http://portainer.localhost

Credits / License

MIT licensed | Copyright © 2020 David Bushell | @dbushell

You can’t perform that action at this time.