Skip to content

Instantly share code, notes, and snippets.

@saniaky
Last active August 15, 2023 09:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saniaky/2fc4a1979ada5b0972cf98c5a6ac24cf to your computer and use it in GitHub Desktop.
Save saniaky/2fc4a1979ada5b0972cf98c5a6ac24cf to your computer and use it in GitHub Desktop.
Docker + Wordpress + Nginx Proxy + Let's encrypt + Watcher
This is a sample configuration that you can use to run multiple website that will be automatically served by nginx-proxy with enabled SSL certificates (from Let's Encrypt).
============= How to backup files inside docker volume? =============
Backup:
docker run --rm \
-v source_volume_name:/source \
-v /host/path/shared:/shared \
ubuntu tar cvf /shared/backup.tar /source
Restore:
docker run --rm \
-v dest_volume_name:/dest \
-v /host/path/shared:/shared \
ubuntu bash -c "tar -C /dest -xvf /shared/backup.tar --strip 1"
Example
Backup:
docker run --rm -v /home/user/shared:/shared -v volume-db:/source ubuntu tar cvf /shared/backup-db.tar /source
docker run --rm -v /home/user/shared:/shared -v volume-wp:/source ubuntu tar cvf /shared/backup-wp.tar /source
Restore
docker run --rm -v volume-db:/dest -v /home/user/shared:/shared ubuntu bash -c "tar -C /dest -xvf /shared/backup-db.tar --strip 1"
docker run --rm -v volume-wp:/dest -v /home/user/shared:/shared ubuntu bash -c "tar -C /dest -xvf /shared/backup-wp.tar --strip 1"
============= Wodpress asks for an FTP credentials during update. =============
This is a common issue whereby the WordPress system can’t write to your /wp-content folder directly.
Fix 1.
open wp-config.php and add define('FS_METHOD','direct');
Fix 2.
Check you permissions:
root@dc1d61c4373a:/var/www# ls -alh
total 12K
drwxr-xr-x. 1 root root 4.0K Nov 28 22:47 .
drwxr-xr-x. 1 root root 4.0K Nov 16 02:06 ..
drwxrwxr-x. 5 www-data www-data 4.0K Dec 1 19:06 html
root@dc1d61c4373a:/var/www/html# ls -alh
total 216K
drwxrwxr-x. 5 www-data www-data 4.0K Dec 1 19:06 .
drwxr-xr-x. 1 root root 4.0K Nov 28 22:47 ..
-rw-rw-r--. 1 1000 1000 125 Dec 1 18:49 .htaccess
-rw-r--r--. 1 www-data www-data 418 Sep 25 2013 index.php
-rw-r--r--. 1 www-data www-data 20K Dec 1 19:05 license.txt
-rw-r--r--. 1 www-data www-data 11K Dec 1 19:05 readme.html
-rw-r--r--. 1 www-data www-data 5.4K May 1 2018 wp-activate.php
drwxr-xr-x. 9 www-data www-data 4.0K Aug 2 20:39 wp-admin
-rw-r--r--. 1 www-data www-data 364 Dec 19 2015 wp-blog-header.php
-rw-r--r--. 1 www-data www-data 1.9K May 2 2018 wp-comments-post.php
-rw-r--r--. 1 www-data www-data 4.1K Dec 1 19:06 wp-config-sample.php
-rw-r--r--. 1 www-data www-data 3.1K Dec 1 19:06 wp-config.php
drwxr-xr-x. 9 www-data www-data 4.0K Dec 1 19:05 wp-content
-rw-r--r--. 1 www-data www-data 3.6K Aug 20 2017 wp-cron.php
drwxr-xr-x. 18 www-data www-data 12K Aug 2 20:39 wp-includes
-rw-r--r--. 1 www-data www-data 2.4K Nov 21 2016 wp-links-opml.php
-rw-r--r--. 1 www-data www-data 3.3K Aug 22 2017 wp-load.php
-rw-r--r--. 1 www-data www-data 37K Jul 16 14:14 wp-login.php
-rw-r--r--. 1 www-data www-data 7.9K Jan 11 2017 wp-mail.php
-rw-r--r--. 1 www-data www-data 16K Oct 4 2017 wp-settings.php
-rw-r--r--. 1 www-data www-data 30K Apr 29 2018 wp-signup.php
-rw-r--r--. 1 www-data www-data 4.6K Oct 23 2017 wp-trackback.php
-rw-r--r--. 1 www-data www-data 3.0K Aug 31 2016 xmlrpc.php
client_max_body_size 64m;
version: '3'
services:
nginx-proxy:
image: jwilder/nginx-proxy:latest
container_name: nginx-proxy
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./certs:/etc/nginx/certs:ro
- ./vhost:/etc/nginx/vhost.d
- ./nginx:/usr/share/nginx/html
- ./custom_proxy_settings.conf:/etc/nginx/conf.d/custom_proxy_settings.conf:ro
labels:
com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true"
nginx-letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion:latest
container_name: nginx-letsencrypt
restart: always
environment:
NGINX_PROXY_CONTAINER: nginx-proxy
# Uncoment to test on Staging
#ACME_CA_URI: https://acme-staging.api.letsencrypt.org/directory
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./vhost:/etc/nginx/vhost.d
- ./certs:/etc/nginx/certs:rw
- ./nginx:/usr/share/nginx/html
watchtower:
image: v2tec/watchtower
container_name: watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /root/.docker/config.json:/config.json
command: container1 container2 --interval 30 --cleanup
networks:
default:
external:
name: network-name
version: '3'
services:
wordpress:
image: wordpress:latest
#ports:
# - "8085:80"
restart: always
volumes:
- ./wordpress:/var/www/html
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: mysql_user
WORDPRESS_DB_PASSWORD: pwd
WORDPRESS_DB_NAME: blog
VIRTUAL_HOST: site.com
LETSENCRYPT_HOST: site.com
LETSENCRYPT_EMAIL: email@site.com
db:
image: mysql:5.7
restart: always
volumes:
- ./mysql:/var/lib/mysql
#ports:
#- "33306:3306"
environment:
MYSQL_ROOT_PASSWORD: pwd
MYSQL_DATABASE: blog
MYSQL_USER: user
MYSQL_PASSWORD: pwd
networks:
default:
external:
name: network-name
file_uploads = On
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment