Skip to content

Instantly share code, notes, and snippets.

@Swiss-Mac-User
Last active July 4, 2023 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swiss-Mac-User/c6c73940bb37b920366c070d36916efd to your computer and use it in GitHub Desktop.
Save Swiss-Mac-User/c6c73940bb37b920366c070d36916efd to your computer and use it in GitHub Desktop.
Docker Compose setup for a Wordpress blog using the official wordpress Docker image, compatible with macOS on Apple Silicon ARM. Full guide can be found here ➝ https://swissmacuser.ch/mamp-to-docker-mac-how-to-migrate/
COMPOSE_PROJECT_NAME="myblog"
OS_PLATFORM="linux/x86_64"
HTTP_PORT="80"
HTTPS_PORT="443"
WP_LOCALHOST="wordpress"
WP_HOST_WEBFILES="./public"
WP_HOST_DATABASEFILES="./mariadb"
WP_WEBROOT="/var/www/html"
WP_DB_NAME="wordpress"
WP_DB_USER="root"
WP_DB_PASSWORD=""
MYSQL_TYPE="mariadb"
MYSQL_VERSION="latest"
MYSQL_PORT="3306"
PHPMYADMIN_LOCALHOST="phpmyadmin"
PHPMYADMIN_PORT="8080"
# The Docker services to run
services:
# A webserver with Wordpress pre-installed
wordpress:
platform: ${OS_PLATFORM}
image: wordpress
container_name: ${COMPOSE_PROJECT_NAME}-wordpress
restart: unless-stopped
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_NAME=${WP_DB_NAME}
- WORDPRESS_DB_USER=${WP_DB_USER}
- WORDPRESS_DB_PASSWORD=${WP_DB_PASSWORD}
hostname: wordpress
domainname: ${WP_LOCALHOST}
ports:
- ${HTTP_PORT}:80
# HTTPS requires nginx service with TLS/SSL Certificates:
#- ${HTTPS_PORT}:443
expose:
- ${HTTP_PORT}
#- ${HTTPS_PORT}
volumes:
- ${WP_HOST_WEBFILES}:${WP_WEBROOT}
# Or with docker-sync:
# - wordpress-webfiles:${WP_WEBROOT}:nocopy
# A MySQL-type database (default: MariaDB)
db:
platform: ${OS_PLATFORM}
image: ${MYSQL_TYPE}:${MYSQL_VERSION}
container_name: ${COMPOSE_PROJECT_NAME}-db
restart: unless-stopped
hostname: database
environment:
- MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=yes
- MARIADB_ROOT_PASSWORD=${WP_DB_PASSWORD}
- MARIADB_DATABASE=${WP_DB_NAME}
# Only required if NOT "root" is used:
#- MARIADB_USER=${WP_DB_USER}
#- MARIADB_PASSWORD=${WP_DB_PASSWORD}
# in some scenarios the following solves Host IP connection issues
#- MARIADB_ROOT_HOST="%"
user: mysql
ports:
- ${MYSQL_PORT}:3306
expose:
- ${MYSQL_PORT}
healthcheck:
test: mysql ${WP_DB_NAME} --user=${WP_DB_USER} --password='${WP_DB_PASSWORD}' --silent --execute "SELECT 1;"
interval: 10s
timeout: 3s
retries: 5
command: [mysqld, --default-authentication-plugin=mysql_native_password, --character-set-server=utf8mb4, --collation-server=utf8mb4_unicode_ci, --innodb_monitor_enable=all, --max-connections=1001, --explicit_defaults_for_timestamp, --ignore-db-dir=lost+found, --default-storage-engine=Aria]
volumes:
- ${WP_HOST_DATABASEFILES}:/var/lib/mysql
# Or with docker-sync:
#- wordpress-database:${MYSQL_DATABASE_PATH}:nocopy
# A Database Management-tool (default: PhpMyAdmin)
db-manager:
image: phpmyadmin:latest
container_name: ${COMPOSE_PROJECT_NAME}-phpmyadmin
hostname: phpmyadmin
domainname: ${PHPMYADMIN_LOCALHOST}
restart: unless-stopped
depends_on:
db:
condition: service_healthy
environment:
- PMA_ARBITRARY=1
# phpMyAdmin connects by default using the MySQL credentials env. Otherwise enable these:
#- PMA_HOST=database
#- MYSQL_USER={WP_DB_USER}
#- MYSQL_PASSWORD=${WP_DB_PASSWORD}
ports:
- ${PHPMYADMIN_PORT}:80
expose:
- ${PHPMYADMIN_PORT}
# When using docker-sync use the following named volumes:
#volumes:
#wordpress-webfiles:
# external: true
#wordpress-database:
# external: true
version: "2"
options:
compose-file-path: "./docker-compose.yml" # Adjust if docker-compose YAML is somewhere else / different name
verbose: true
syncs:
# sync_strategy: see https://docker-sync.readthedocs.io/en/latest/getting-started/configuration.html#sync-strategy
wordpress-webfiles:
src: "${WP_HOST_WEBFILES}"
sync_strategy: "native_osx" # Fast enough for web files
sync_excludes: [ ]
wordpress-database:
src: "${WP_HOST_DATABASEFILES}"
sync_strategy: "unison" # Performance boost for database storage
127.0.0.1 wordpress
127.0.0.1 phpmyadmin
MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment