What is the best way to setup latest wordpress blog using docker?

Dream of any developer is to keep things portable and what would be more awesome thank to use Docker for your WordPress post right? I had plenty of hiccups in the setup like permission, portability, port and most annoying of all ssl compatibility.

Assuming that you have already installed docker-compose, you need a compose file as following.


version: '3.2'
services:
  wordpress:
    image: wordpress:5.2.0-php7.3-apache
    restart: always
    volumes:
        - "/etc/passwd:/etc/passwd:ro"
        - "/etc/group:/etc/group:ro"
        - ./wordpress/:/var/www/html/
    ports:
        - 91:80
    environment:
        - WORDPRESS_DB_PASSWORD=pass_is
        - WORDPRESS_TABLE_PREFIX=tb_
        - APACHE_RUN_USER=my_user
        - APACHE_RUN_GROUP=my_group
  mysql:
    image: mysql:5.7
    restart: always
    volumes:
        - type: bind
          source: ./mysql
          target: /var/lib/mysql
    environment:
        - MYSQL_ROOT_PASSWORD=pass_is

Solving the HTTPS – wordpress behind https proxy (ssl)

If you are using nginx behind https, you have to forward proto as https is

proxy_set_header X-Forwarded-Proto https;


server {
    listen 443 ssl;
    server_name yourdomain.com;
    index index.php index.html index.htm;
    ssl_trusted_certificate ./fullchain.pem;
    ssl_certificate ./fullchain.pem;
    ssl_certificate_key ./privkey.pem;
    root /usr/local/nginx/html/;
    location / {
        try_files $uri @app;
    }
    location @app {
        proxy_set_header X-Forwarded-Proto https;
        proxy_pass http://127.0.0.1:8888;
        include .common/proxy.common;
    }
}

Back up your Blog.

sudo docker exec -it _mysql_1 mysqldump -uroot -ppass_id --all-databases > ./mysql-backup/backup.sql

Restore your Blog.

docker exec -i _mysql_1 mysql -uroot -ppass_id < ./backup.sql

Takeaways:

  1. Embedded passwd and group file.
  2. Setting host user and group for folder permission.
  3. We are mounting wordpress folder so that your files can be added to git as well and you can work on wp-config.php without any issues.
  4. MySQL too will have data folder.
  5. You can easily move setup to different server in matters of mins.
What is the best way to setup latest wordpress blog using docker?

8 thoughts on “What is the best way to setup latest wordpress blog using docker?

  1. The solution worked properly and I used proxy ssl for it. Only problem was to picking only wp-content to add to git. Otherwise all great.

Leave a Reply to Tromp Nicholas Cancel reply

Your email address will not be published. Required fields are marked *

Scroll to top