Originally published at docs.bitnami.com.
Why WordPress and Why Containers for Local Development?
When you are searching for an open-source CMS to create your blog or website, chances are that you finally chose WordPress.
WordPress is easy to use and includes a lot of plugins and themes enabled by default so you can run your website in a matter of minutes.
The best way to start developing locally is to use containers. They offer many of the same advantages as developing in VMs, but with lower overhead in terms of developer effort and development machine resources.
Bitnami containers are a great resource for local development: they allow you to save a lot of time in coding and ensure that you launch always the latest and secure application image.
As a developer, you may probably want to add some customizations to the default configuration that Bitnami delivers in its containers. This tutorial shows how to add and activate both a custom plugin and a theme for the first run.
Set Up Prerequisites
Before starting, make sure that you have already set up the following:
- A Docker environment installed and configured.
- A Docker Hub account.
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.
1) Clone the Bitnami Docker WordPress repository and change to the directory that contains all files:
git clone https://github.com/bitnami/bitnami-docker-wordpress.git cd bitnami-docker-wordpress
The next 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/).
2) In the rootfs/ directory, create a file named download-extra.sh with the following content:
#!/bin/bash curl -o /tmp/bbpress2.5.14.zip https://downloads.wordpress.org/plugin/bbpress.2.5.14.zip curl -o /tmp/gambit.1.5.3.zip https://downloads.wordpress.org/theme/gambit.1.5.3.zip unzip /tmp/bbpress.2.5.14.zip -d /opt/bitnami/wordpress/wp-content/plugins unzip /tmp/gambit.1.5.3.zip -d /opt/bitnami/wordpress/wp-content/themes
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.
1) Open the Dockerfile (5/debian-9/Dockerfile) and add the unzip packages to the RUN install_packages command list:
# Install required system packages and dependencies RUN install_packages unzip libbz2-1.0 libc6 libcomerr2 libcurl3 libexpat1 libffi6 libfreetype6 libgcc1 libgcrypt20 libgmp10 libgnutls30 libgpg-error0 libgssapi-krb5-2 libhogweed4 libicu57 libidn11 libidn2-0 libjpeg62-turbo libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 libldap-2.4-2 liblzma5 libmemcached11 libmemcachedutil2 libncurses5 libnettle6 libnghttp2-14 libp11-kit0 libpcre3 libpng16-16 libpq5 libpsl5 libreadline7 librtmp1 libsasl2-2 libsqlite3-0 libssh2-1 libssl1.0.2 libssl1.1 libstdc++6 libsybdb5 libtasn1-6 libtidy5 libtinfo5 libunistring0 libxml2 libxslt1.1 libzip4 zlib1g
2) Add the RUN bash download-extra.sh command under the COPY rootfs/ line:
COPY rootfs / RUN bash download-extra.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.
1) Open the app-entrypoint.sh (5/debian-9/rootfs/app-entrypoint.sh) file and add the following:
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 latest version of the WordPress Docker image packaged by Bitnami. To point to your custom image, it is necessary to change that value in the docker-compose.yml.
In the next steps, remember to replace "DOCKER_USERNAME/my-custom-wordpress" with the username of your Docker account and the name of your image, respectively.
wordpress: image: 'DOCKER_USERNAME/my-custom-wordpress:latest'
Step 5: Build the Docker Image
Let's build the Docker image.
1) Execute the docker build command within the directory that contains the Dockerfile (5/debian-9/):
cd 5/debian-9/ docker build -t DOCKER_USERNAME/my-custom-wordpress:latest .
2) 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
To test locally your custom image, it is necessary to run the container.
1) Execute the docker-compose up command:
If everything went well, you should see an output message similar to this:
2) Enter http://localhost in your web browser and check that the theme is already activated:
3) 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:
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 guide uses Docker Hub, but you can select one of your own choice such as:
1) Log in to Docker Hub
2) Push the image to your Docker Hub account:
docker push DOCKER_USERNAME/my-custom-app:latest
Congratulations! You have customized a WordPress Docker image, tested and built it, and now it is available in Docker Hub and ready to be deployed in a production scenario!
Deploy a Custom WordPress Image on a Kubernetes Cluster Using Bitnami Helm Charts
Top comments (2)
For those reading and struggling with this tuto as I did, here is my repo hub.docker.com/r/franz333/tuto-wp
Not sure if it's the right way to do it but it's working and it solved bugs encountered following this tutorial.
I managed with the help of answers found in the issues descriptions (github.com/bitnami/bitnami-docker-...) and with efforts trying, having errors, correcting, ...
Thanks for the article.
I have done exactly what you explained in the article but it seems I am having an issue connecting to the database.. github.com/bitnami/bitnami-docker-...
Do you have any suggestion to help me fix this?
THanks you in advance.