Containerizing WordPress.

Visits: 1058

I would like to containerize my sites, especially this site.

Here are some links that I will use for guidance, wish me luck.

  • create an instance with docker and docker-compose
  • copy over the database export with “mysqldump –u[user name] –p[password] [database name] > [dump file] “and a tarZ of the wp-content files
  • create dirs to store the wp-content, this will be a docker mounted volume
  • create initdb.d dir to be mounted as a volume, put the sql export in there. mysql reads and runs that if it’s DB dir is empty
  • edit the docker-compose.yaml file below, you might want to delete the table_prefix if you use the default wp_
  • run “docker-compose up” after it work re-run with “docker-compose up -d”
  • It takes a while to work, after you get can’t connect to DB errors, the db does magically come up
  • account www or apache should be created on the server and ownership of the files should go  to it, indeed perhaps create this user in docker group too without root access, for security. I used Ubuntu 19 which comes with user www-data so I just changed the owner to that for www-content, then I was able to update the plugins.
version: '2'

     image: mysql:5.7
     restart: always
      - "3306:3306"
       MYSQL_ROOT_PASSWORD: wordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress
        - ./database/data:/var/lib/mysql
        - ./database/initdb.d:/docker-entrypoint-initdb.d
     image: wordpress:latest
     working_dir: /var/www/html
        - db
        - "80:80"
        - "/home/steve/wp-content/:/var/www/html/wp-content/"
     restart: always
       - WORDPRESS_DB_HOST=db:3306
       - WORDPRESS_DB_PASSWORD=wordpress
       - WP_DEBUG=true
       - WP_DEBUG_LOG=true
       - WP_DEBUG_DISPLAY=true
       - WORDPRESS_TABLE_PREFIX=linuxguru_