Skip to content

Instantly share code, notes, and snippets.

@roy-n-roy
Last active October 6, 2019 11:36
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 roy-n-roy/75370b28f639fdb489ca321001717eb8 to your computer and use it in GitHub Desktop.
Save roy-n-roy/75370b28f639fdb489ca321001717eb8 to your computer and use it in GitHub Desktop.
Wordpress on Docker.
version: '3.1'
services:
https-portal:
image: steveltn/https-portal:1
container_name: https-portal
ports:
- '443:443'
- '80:80'
links:
- wordpress
restart: always
environment:
DOMAINS: 'mydomain.com -> http://wordpress'
STAGE: 'production'
#FORCE_RENEW: 'true'
logging: # logをfluentdで収集する場合
driver: 'fluentd'
options:
fluentd-address: 'localhost:24224'
tag: 'docker.{{.Name}}'
volumes:
- ssl-certs:/var/lib/https-portal
wordpress:
image: wordpress:latest
container_name: wordpress
restart: always
environment:
WORDPRESS_DB_HOST: wpdb
WORDPRESS_DB_USER: dbuser
WORDPRESS_DB_PASSWORD: dbpass
WORDPRESS_DB_NAME: mydomain_wp
logging:
driver: 'fluentd'
options:
fluentd-address: 'localhost:24224'
tag: 'docker.{{.Name}}'
volumes:
- wp_volume:/var/www/html
wpdb:
image: mysql:5.7
container_name: wpdb
restart: always
environment:
MYSQL_DATABASE: mydomain_wp
MYSQL_USER: dbuser
MYSQL_PASSWORD: dbpass
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
logging:
driver: 'fluentd'
options:
fluentd-address: 'localhost:24224'
tag: 'docker.{{.Name}}'
volumes:
- wpdb_volume:/var/lib/mysql
ddclient: # Google DomainsなどのDDNS更新用
image: linuxserver/ddclient
container_name: ddclient
environment:
- PUID=1001
- PGID=4
- TZ=Asia/Tokyo
logging:
driver: 'fluentd'
options:
fluentd-address: 'localhost:24224'
tag: 'docker.{{.Name}}'
volumes:
- ./conf:/config
restart: unless-stopped
volumes:
wpdb_volume:
driver: local
wp_volume:
driver: local
ssl-certs:
driver: local
#!/bin/bash -f
# Wordpresのファイルとデータベースをバックアップします
#docker-compose.ymlファイル
yaml_f=docker-compose.yml
#バックアップディレクトリ
backup_dir="backup_"`date '+%Y%m%d%H%M%S'`
#docker-compose.ymlからデータベース情報を取得
set $(grep "MYSQL_DATABASE" ${yaml_f} | tr ':' ' ')
db_name=${2}
set $(grep "MYSQL_USER" ${yaml_f} | tr ':' ' ')
db_user=${2}
set $(grep "MYSQL_PASSWORD" ${yaml_f} | tr ':' ' ')
db_pass=${2}
#ディレクトリ作成
mkdir ${backup_dir}
#Wordpresファイルバックアップ
docker run --rm --volumes-from wordpress -v ${PWD}/${backup_dir}:/backup busybox tar cf /backup/wp_backup.tar html -C /var/www
#Wordpressデータベースバックアップ
docker run --rm --volumes-from wpdb -v ${PWD}/${backup_dir}:/backup busybox tar cf /backup/db_backup.tar mysql -C /var/lib
bzip2 ${PWD}/${backup_dir}/wp_backup.tar ${PWD}/${backup_dir}/db_backup.tar
chown -R $(whoami):adm ${backup_dir}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment