While the official images should provide you with a fully functioning usable image you may sometimes need to install additional software, in this case we are going to look at installing WordPress CLI using the official WordPress image.
WordPress CLI is a set of command line tools which allow you to manage your WordPress configuration and installation; for more information, see http://wp-cli.org/.
You can find a copy of the Dockerfile
below in the /chapter02/wordpress-custom/
folder in the repo, as you can see we are just running RUN
and COPY
instructions:
# Adds wp-cli to the offical WordPress image FROM wordpress:latest MAINTAINER Russ McKendrick<[email protected]> # Install the packages we need to run wp-cli RUN apt-get update && apt-get install -y sudo less mysql-client && curl -o /bin/wp-cli.pharhttps://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar # Copy the wrapper for wp-cli and set the correct execute permissions COPY wp /bin/wp RUN chmod 755 /bin/wp-cli.phar /bin/wp # Clean up the installation files RUN apt-get clean &&rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/
You can build the image using the following command:
docker image build -t wordpress-custom .
Once it has finished building use the following command to check the image:
docker image ls
However, as we discovered earlier in this chapter it is easier to launch WordPress using Docker Compose, before we do lets remove the image we just built by running:
docker image rm wordpress-custom
Docker Compose can also trigger builds. Our updated docker-compose.yml
file can be found in the /chapter02/wordpress-custom/
folder and below:
version: "3" services: mysql: image: mysql volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress wordpress: depends_on: - mysql build: ./ ports: - "8080:80" restart: always environment: WORDPRESS_DB_PASSWORD: wordpress volumes: db_data:
As you can see, it is almost exactly the same as our original docker-compose.yml
apart from now we have a line that says build: ./
" rather than image: wordpress
".
To launch our WordPress installation, we simply need to run the following command:
docker-compose up -d
This will pull and build the container images, once complete you should see something like the following in your terminal:
Going to http://localhost:8080/
should show you the installation screen, however, we are going to typing a few commands to configure WordPress using the WordPress CLI.
First, let's check the version of WordPress we are working with by running:
docker-compose exec wordpress wp core version
This will connect to the WordPress service and run the wp core version
command, then return the output:
Next, we are going to install WordPress using the wp core install
command, change the title
, admin_user
, admin_password
and admin_email
values as you like:
docker-compose exec wordpress wp core install --url=http://localhost:8080/ --title=Testing --admin_user=admin --admin_password=adminpasswIt ord [email protected]
Once the command has finished running you should receive a message saying Success: WordPress installed successfully:
Going to http://localhost:8080/
should show you a WordPress site rather than an installation prompt:
Once you have finished with your WordPress installation you can stop and remove it by running:
docker-compose stop docker-compose rm
Now we know how to build an image we are going to look at a few different ways to share them.
18.223.195.164