Develop Locally A Custom WordPress Using Bitnami Containers

Introduction

Bitnami containers provide you with a ready-to-go environment for the development framework of your choice backed by Bitnami. By selecting a Bitnami container for local development, you can save a lot of time in coding as well as you benefit from having always the latest and more secure application image. As a developer, you may probably want to add some customizations to the default configuration that Bitnami delivers in its containers.

In this tutorial, you will learn how to use a Bitnami container to have a boilerplate from which you can implement all the customizations that your project demands. This guide uses the Bitnami WordPress Docker container as an example and will show you, step by step, how to add and activate both a custom plugin and a theme from the first run.

Assumptions and prerequisites

This guide makes the following assumptions:

The following are the steps you will complete in this guide:

  • Step 1: Create a script to add a plugin and a theme
  • Step 2: Edit the Dockerfile to add the custom script
  • Step 3: Activate the plugin and theme at initialization time
  • Step 4: Edit the docker-compose.yml file to point to your image
  • Step 5: Build the Docker image
  • Step 6: Test the Docker image and access locally to your custom application
  • Step 7: Publish the Docker image

Step 1: Create a script to add a plugin and a theme

To begin the process, you need to obtain the Bitnami Docker image for WordPress. To do so, clone the Bitnami Containers repository as shown below. Then, change to the directory that contains all files:

git clone https://github.com/bitnami/containers.git
cd containers/bitnami/wordpress

The first step is to create a script to specify which are the plugins/themes you want to install in your WordPress. This script will contain the instructions to download and uncompress the plugin and the theme files as well as the path where they should be installed (/opt/bitnami/wordpress/wp-content/):

  • Create a file in the rootfs/ directory named download-extra.sh:
vim 6/debian-12/rootfs/download-extra.sh
  • Add the following lines:
#!/bin/bash
curl -o /tmp/bbpress.2.6.4.zip https://downloads.wordpress.org/plugin/bbpress.2.6.4.zip
curl -o /tmp/gambit.1.6.5.zip https://downloads.wordpress.org/theme/gambit.1.6.5.zip
unzip /tmp/bbpress.2.6.4.zip -d /opt/bitnami/wordpress/wp-content/plugins
unzip /tmp/gambit.1.6.5.zip -d /opt/bitnami/wordpress/wp-content/themes
Tip

For the sake of simplicity, this guide shows how to install an official WordPress plugin and theme. Replace these examples with the path where the plugins you want to add are located.

Step 2: Edit the Dockerfile to add the custom script

To install the plugins and themes you have selected in the first run, it is necessary to indicate in the Dockerfile where are the instructions to perform that action. Follow the steps below:

  • Open the Dockerfile with your favorite editor:
vim 6/debian-12/Dockerfile
  • Add the RUN bash download-extra.sh command under the COPY rootfs / line:
COPY rootfs /
RUN bash download-extra.sh
  • Remove the USER 1001 directive to be able to launch the container as root user so your Dockerfile should look as shown below:
EXPOSE 8080 8443
ENTRYPOINT [ "/app-entrypoint.sh" ]

Step 3: Activate the plugin and theme at initialization time

To initialize the container with the installed plugin and theme already activated, it is necessary to add this action in the application entrypoint script. To do so:

  • Open the app-entrypoint.sh file with your favorite editor:
vim 6/debian-12/rootfs/app-entrypoint.sh
  • Add the following lines:
nami_initialize apache php mysql-client wordpress
su daemon -s /bin/bash -c '/opt/bitnami/wp-cli/bin/wp plugin activate bbpress'
su daemon -s /bin/bash -c '/opt/bitnami/wp-cli/bin/wp theme activate gambit'
info "Starting wordpress... "

Step 4: Edit the docker-compose.yml file to point to your image

By default, the docker-compose.yml file is pointing to the bitnami/wordpress:X.Y.Z image. Being bitnami the Docker username and "X.Y.Z" the latest version of the WordPress Docker image packaged by Bitnami. Replace these values with the following (remember to replace DOCKER_USERNAME placeholder with the username of your Docker account):

wordpress:
   image: 'DOCKER_USERNAME/my-custom-wordpress:latest'
Tip

Using latest as the tag of the image prevents you to the need of updating that tag any time you perform changes in the container.

Step 5: Build the Docker image

The next step is to build the Docker image using the docker build command. This should be executed within the directory that contains the Dockerfile. Replace the DOCKER_USERNAME placeholder with the username of your Docker Hub account:

cd 6/debian-12/
docker build -t DOCKER_USERNAME/my-custom-wordpress:latest .

When the build finishes you can check that the image has been added to the local repository by executing:

docker images | grep my-custom-wordpress

Step 6: Test the Docker image and access locally to your custom application

The last step is to test locally your custom image by running the container. After that, you will be able to access the application by browsing http://localhost. To start running the container, execute the docker-compose up command:

docker-compose up

If everything went well, you should see an output similar to this:

Container up
  • Enter http://localhost in your web browser and check that the theme is already activated:
Theme active
  • Log in to the WordPress admin panel using the default credentials: username user and password bitnami. Navigate to the "Plugins" section. You will see the BBplugin already installed and activated:
Plugin active

Congratulations! You have a WordPress Docker container running locally using a custom plugin and theme!

Step 7: Publish the Docker image

Now that your Docker image is built and contains your application code, you can upload it into a public registry. This tutorial uses Docker Hub, but you can select one of your own choice such as:

To upload the image to Docker Hub, follow the steps below:

  • Log in to Docker Hub:
docker login
  • Push the image to your Docker Hub account. Replace the DOCKER_USERNAME placeholder with the username of your Docker Hub account and my-custom-app:latest with the name and the version of your Docker image:
docker push DOCKER_USERNAME/my-custom-app:latest
  • Confirm that you see the image in your Docker Hub repositories dashboard.

This tutorial is part of the series

From development to production - customize and secure your WordPress deployment

Learn how to create a custom WordPress container image, deploy it on a Kubernetes production cluster, and secure your deployment with TLS and Let's Encrypt SSL certificates.