Local WordPress Development with Docker and Docker Compose part 3

👓In this series: part 1, part 2

In my previous post i went through tips and tricks to help you run a smooth WordPress app using Docker-compose.

For this part I’ll show you how you can use your own Dockerfile with an existing or own

Dockerfile

Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.

With a Dockerfile you can extend an existing Docker image, for example like in Part 1. You can also install extra packages of your choice, and of course much more.

Let’s create our own Dockerfile:

FROM urre/wordpress-nginx-docker-compose-image

# Install wp-cli
RUN curl -o /bin/wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
RUN chmod +x /bin/wp-cli.phar
RUN cd /bin && mv wp-cli.phar wp

I’m using my own docker image urre/wordpress-nginx-docker-compose-image image. A slightly modified wordpress:php7.2-fpm with the only difference that it doesn’t download WordPress core files. We do that with Composer ourself.

If we want to build the image we can simply use: docker build .

Let Compose build from Dockerfile

Update docker-compose.yml to build from our Dockerfile

  wordpress:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: myapp-wordpress
    ...

Update our wordpress service with the build section above.

Start

Start things up like before

docker-compose up -d

When making changes to the Dockerfile : Use docker-compose up -d –force-recreate –build

💥 Done!

Extra: Set up Automated Builds using GitHub and Docker Hub

Docker Hub can automatically build images from source code in an external repository and automatically push the built image to your Docker repositories.

  1. Create a DockerHub repository. Again, I use the public, but in production, you should only do private ones.
  2. Under the Builds tab, ceate Automated Builds and select the code repository service (GitHub ) where the image’s source code is stored.
  3. Configure the Automated Build to your needs

Overview page

Recent builds

Let me know if you have any questions!

Example repo