<aside> 💡 Using Local! You can create very quickly a simple wordpress on localhost with a domain website.local. You can also backup your site and drag-n-drop into Local for using locally. However, Local are not always working with the custom themes.

</aside>

WP basic without backup

Make a folder name mysite containing,

mysite
|-- docker-compose.yml  # main file
|-- backup              # contains backup files using AIO WP Migration plugins
|-- plugins             # contains plugins
|-- themes              # contains templates
|-- wordpress           # main site's sources

In the docker-compose.yml,

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
        - 8080:80
    environment:
        WORDPRESS_DB_HOST: db
        WORDPRESS_DB_USER: exampleuser
        WORDPRESS_DB_PASSWORD: examplepass
        WORDPRESS_DB_NAME: exampledb
    volumes:
        - './html/:/var/www/html/'
        - './plugins/:/var/www/html/wp-content/plugins/'
        - './themes/<theme>/:/var/www/html/wp-content/themes/<theme>'

  db:
    image: mysql:5.7
    restart: always
    environment:
        MYSQL_DATABASE: exampledb
        MYSQL_USER: exampleuser
        MYSQL_PASSWORD: examplepass
        MYSQL_RANDOM_ROOT_PASSWORD: '1'

Start the container,

cd mysite
docker-compose up -d
# check running containers
docker ps -a

Browse http://localhost:8080 to install wordpress by gui.

Debug

In the case you wanna see the list of users or access to the mysql environement,

# connect to MySQL running container
docker exec -it <container_db> bash

# connect to mysql database
mysql -u wordpress -p

# list all users
SELECT host, user FROM mysql.user;

Install WP-CLI

# Download wp-cli
curl -O <https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar>
# Make it executable
chmod +x wp-cli.phar
# Move it into /usr/local/bin/wp
sudo mv wp-cli.phar /usr/local/bin/wp
# Check whether the installation worked
wp --info

For example, activate all-in-one-wp-migration (already copied / placed in folder plugins)

wp plugin activate all-in-one-wp-migration --allow-root

Errors & warnings

apache2: Could not reliably determine the server's fully qualified domain name
# enter to wordpress container's bash
docker exec -it <container> bash
# add
echo 'ServerName localhost' >> /etc/apache2/apache2.conf
# restart apache/container
service apache2 restart