Wordpress Docker

Anh-Thi Dinh
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.

WP basic without backup

Make a folder name mysite containing,
2|-- docker-compose.yml  # main file
3|-- backup              # contains backup files using AIO WP Migration plugins
4|-- plugins             # contains plugins
5|-- themes              # contains templates
6|-- wordpress           # main site's sources
In the docker-compose.yml
1version: '3.1'
5  wordpress:
6    image: wordpress
7    restart: always
8    ports:
9        - 8080:80
10    environment:
11        WORDPRESS_DB_HOST: db
12        WORDPRESS_DB_USER: exampleuser
13        WORDPRESS_DB_PASSWORD: examplepass
14        WORDPRESS_DB_NAME: exampledb
15    volumes:
16        - './html/:/var/www/html/'
17        - './plugins/:/var/www/html/wp-content/plugins/'
18        - './themes/<theme>/:/var/www/html/wp-content/themes/<theme>'
20  db:
21    image: mysql:5.7
22    restart: always
23    environment:
24        MYSQL_DATABASE: exampledb
25        MYSQL_USER: exampleuser
26        MYSQL_PASSWORD: examplepass
Start the container,
1cd mysite
2docker-compose up -d
3# check running containers
4docker ps -a
Browse http://localhost:8080 to install wordpress by gui.


In the case you wanna see the list of users or access to the mysql environement,
1# connect to MySQL running container
2docker exec -it <container_db> bash
4# connect to mysql database
5mysql -u wordpress -p
7# list all users
8SELECT host, user FROM mysql.user;

Install WP-CLI

1# Download wp-cli
2curl -O <https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar>
3# Make it executable
4chmod +x wp-cli.phar
5# Move it into /usr/local/bin/wp
6sudo mv wp-cli.phar /usr/local/bin/wp
7# Check whether the installation worked
8wp --info
For example, activate all-in-one-wp-migration (already copied / placed in folder plugins)
1wp plugin activate all-in-one-wp-migration --allow-root

Errors & warnings

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

1Could not create directory on mounted volume
1# enter to wordpress container's bash
2docker exec -it <container> bash
3# then
4chown -R www-data:www-data /var/www

1Your file exceeds the maximum upload size for this site: 2 MB
1# .htaccess
2php_value upload_max_filesize 400M
3php_value post_max_size 400M
4# php_value memory_limit 256M
5# php_value max_execution_time 300
6# php_value max_input_time 300


Loading comments...