Deploying WordPress with Docker Compose on Ubuntu

How-to deploy custom WordPress themes and plugins in a local container handled by Docker Compose on Ubuntu

Logo of Docker
Docker

Docker CE (Community Edition)

$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
$ sudo usermod -aG docker username

Docker Compose

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
  db:
image: mysql:latest
# image: mariadb:latest # MariaDB
command: mysqld --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- db-data:/var/lib/mysql
environment:
MYSQL_DATABASE: database
MYSQL_ROOT_PASSWORD: password
wp:
depends_on:
- db
links:
- db
image: wordpress:latest
restart: always
volumes:
- ./path/to/wordpress:/var/www/html
- ./path/to/wordpress/plugin:/var/www/html/wp-content/plugins/foo
- ./path/to/wordpress/theme:/var/www/html/wp-content/themes/bar
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: database
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: password
$ cd /path/to/docker-compose.yml
$ docker-compose up -d

Federico Moretti is a front-end developer from Varese who provides solutions in HTML, CSS and JavaScript for small and medium-sized businesses as a freelancer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store