Install WordPress using Docker

Carinnan

Using Images Provided by Bitnami #

Since the WordPress deployment package described here is no longer available, I am trying the Docker image still provided by Bitnami. Don’t ask why—it’s just a habit.

Install Docker Engine and Docker Compose first. Refer to the official Docker manual.

For the standalone docker-compose command:

1
2
3
4
5
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

docker-compose --version

To upgrade Docker Compose, run the commands above again to replace the executable.

Then run the Docker image as instructed in the Bitnami documentation:

1
2
curl -sSL https://raw.githubusercontent.com/bitnami/containers/main/bitnami/wordpress/docker-compose.yml > docker-compose.yml
docker-compose up -d

That is mostly it. Edit docker-compose.yml—especially its environment variables—to initialize your site properly.

The configuration also starts a MariaDB image; refer to its documentation.

Some useful commands:

1
2
docker ps -a
docker volume ls

Official WordPress Image #

Then I tried the official WordPress image. The process is almost the same; refer to the image documentation. I find it easy to use Docker Compose to start the container.

Increasing the Upload Limit #

When I tried to upload photos to the media library, an error said that the maximum upload size was 2 MB. Come on, it was already 2023—what image quality can you get in 2 MB?

First, enter the container:

1
docker exec -it $container_ID /bin/bash

There are two ways to solve it:

  • Edit /var/www/html/.htaccess and add:
1
2
3
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value memory_limit 256M
  • Find and edit php.ini, then add:
1
2
3
upload_max_filesize = 128M
post_max_size = 128M
memory_limit = 512M

I created a php.ini file under /usr/local/etc/php/conf.d/. Your path may differ, although it should be the same when using the official WordPress image.