duaneleem
1/20/2018 - 6:05 AM

Automated Docker Containers for WordPress

Used to create a development (or production) environment of WordPress using the official Docker WP from the store.

One huge plus to this if you decide to use it for development, check out the .htaccess file. It rewrites requests to the /wp-content/uploads folder so you don't have to add that to your dev environment :)

I opened the MySQL port to listen to 3406 on our local computer so you can use your favorite MySQL CLI or application to manage your DB server.

# ================================================================================
#   Redirects uploads to production.
# ================================================================================
<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^wp-content/uploads/(.*)$ https://www.some-website.com/wp-content/uploads/$1 [R=301,NC,L]
</IfModule>

# ================================================================================
#   Docker WordPress
# ================================================================================
# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
# END WordPress
version: '3'

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    ports:
      - "3406:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress_user
      MYSQL_PASSWORD: wordpress_password

  wordpress:
    depends_on:
      - db
    image: wordpress:4.9.1-php7.0-apache
    volumes:
      - "./wp-content/themes:/var/www/html/wp-content/themes"
      - "./wp-content/plugins:/var/www/html/wp-content/plugins"
      - "./wp-content/uploads:/var/www/html/wp-content/uploads"
      - "./.htaccess:/var/www/html/.htaccess"
    ports:
      - "8080:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress_user
      WORDPRESS_DB_PASSWORD: wordpress_password

volumes:
    db_data: