{"id":2344,"date":"2016-03-01T13:25:13","date_gmt":"2016-03-01T11:25:13","guid":{"rendered":"https:\/\/upcloud.com\/global\/us\/resources\/tutorials\/deploy-wordpress-with-docker-compose\/"},"modified":"2026-04-23T13:58:39","modified_gmt":"2026-04-23T12:58:39","slug":"deploy-wordpress-with-docker-compose","status":"publish","type":"tutorial","link":"https:\/\/upcloud.com\/global\/resources\/tutorials\/deploy-wordpress-with-docker-compose\/","title":{"rendered":"How to deploy WordPress with Docker Compose"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">WordPress is one of the most popular content management software (CMS) due to its multitude of features and ease of use. However, setting up a new web host environment can be time-consuming especially if you need to do it often. Docker Compose manages to simplify the installation process to a single deployment command&nbsp;greatly reducing the time and effort required. Deploying&nbsp;WordPress with Docker Compose is&nbsp;fast and easy after the first time setup.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/wordpress-docker-compose.png\" alt=\"WordPress using Docker Compose\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Docker is a container platform that allows simple and fast software installations on any system or&nbsp;OS. It wraps the piece of software in a complete file system that includes everything it needs to run such as code, runtime, system tools and libraries. This allows anyone to package an application with its dependencies into a standardized building block.<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/signup.upcloud.com\/\">Try UpCloud for free!<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Docker<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Using Docker Compose requires having the Docker daemon running on your cloud server. Installing Docker itself is already easy. Firstly run the usual update command for your system to make sure you have the latest source lists.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Debian and Ubuntu\nsudo apt-get update\n# CentOS\nsudo yum update<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check that you have the&nbsp;curl command line utility.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl -V<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It comes preinstalled with most Linux distributions, but&nbsp;if it can not be found,&nbsp;install it manually with the appropriate command for your OS.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Debian and Ubuntu\nsudo apt-get install curl\n# CentOS\nsudo yum install curl<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use the command below to download and install Docker. The process requires root privileges so you will be asked for your <em>sudo<\/em> password on any non-root user.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl -fsSL https:\/\/get.docker.com\/ | sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Towards the end of the installation process, you will see a suggestion&nbsp;to add your username to the Docker users group. Doing this allows you to run Docker commands without needing to invoke <em>sudo<\/em> every time.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo usermod -aG docker&nbsp;<span style=\"color: #ff0000;\">username<\/span><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Log out and back in again after adding yourself to the Docker users group before continuing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can check&nbsp;that the installation was successful with the following test program:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker run hello-world<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should&nbsp;see an output similar to the example below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Unable to find image 'hello-world:latest' locally\nlatest: Pulling from library\/hello-world\n...\nHello from Docker.\nThis message shows that your installation appears to be working correctly.\n...<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the command does not work immediately, restart the Docker service with the following and try to run the hello-world app again.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl restart docker<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Docker should now be installed and working correctly. Continue on below with rest of the guide to install Docker Compose.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Docker Compose<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">While installing applications in containers with simple commands is already easy enough, it still requires memorizing those commands and their parameters. Docker-compose allows combining&nbsp;the installation process for multiple containers. Install the additional components for Docker using the procedure&nbsp;below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, temporarily switch to your root account.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo -i<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use the install script below to download and apply the docker-compose packet.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl -L https:\/\/github.com\/docker\/compose\/releases\/download\/1.24.0\/docker-compose-$(uname -s)-$(uname -m) -o \/usr\/local\/bin\/docker-compose<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Set&nbsp;the execution permissions to it with:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod +x \/usr\/local\/bin\/docker-compose<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And then exit the root user account to return to your normal username.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">exit<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should now have the docker-compose application installed and available, test it by checking for the version number.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker-compose -v<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">docker-compose version 1.24.0, build 0aa59064<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With the Docker Compose installed you are now ready to start configuring your containerized WordPress environment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring WordPress&nbsp;with Compose<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress is&nbsp;<a href=\"https:\/\/hub.docker.com\/_\/wordpress\/\" target=\"_blank\" rel=\"noopener\">officially available on Docker Hub<\/a>&nbsp;and easy to set up,&nbsp;but it will not create a working website by itself, it requires a database to store the&nbsp;content.&nbsp;MariaDB&nbsp;is a community-developed relational&nbsp;database management system and a drop-in replacement for MySQL. It is also&nbsp;<a href=\"https:\/\/hub.docker.com\/_\/mariadb\/\" target=\"_blank\" rel=\"noopener\">officially available on Docker<\/a> and provides easy instructions with up to date images.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Setting up containers with Docker Compose works by creating a <em>Dockerfile<\/em> and <em>docker-compose.yml<\/em> in the desired working directory. Start off by creating your working directory, e.g. <em>wordpress-compose<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir &nbsp;~\/wordpress-compose &amp;&amp; cd ~\/wordpress-compose<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Next, create a <em>docker-compose.yml<\/em>&nbsp;file. This will tell docker how to configure and start the WordPress and MariaDB containers.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano docker-compose.yml<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Copy the example underneath and set the parameters in the file. Replace the database <span style=\"color: #ff0000;\">password<\/span> and <span style=\"color: #ff0000;\">public_ip<\/span>&nbsp;with values appropriate to your cloud server. Make sure the password is the same for both environment variables so that WordPress will be able to access the database.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">wordpress:\n    image: wordpress\n    links:\n     - mariadb:mysql\n    environment:\n     - WORDPRESS_DB_PASSWORD=<span style=\"color: #ff0000;\">password\n<\/span>     - WORDPRESS_DB_USER=root\n    ports:\n     - 80:80\n    volumes:\n     - .\/html:\/var\/www\/html\nmariadb:\n    image: mariadb\n    environment:\n     - MYSQL_ROOT_PASSWORD=<span style=\"color: #ff0000;\">password<\/span>\n     - MYSQL_DATABASE=wordpress\n    volumes:\n     - .\/database:\/var\/lib\/mysql\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When you are done editing the compose file, save it and exit the editor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now&nbsp;create the new containers with the command below.&nbsp;This starts both containers in the background and leaves them running. If you wish to see the output from the containers just leave out the <em>-d<\/em> to deploy the applications in the foreground.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker-compose up -d<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Wait for the installation to finish. You will see something like the example output below once the process is complete.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Creating wordpress-compose_mariadb_1 ... done\nCreating wordpress-compose_wordpress_1 ... done<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can then open the public IP or domain of your WordPress server in your web browser to test the installation. You should be redirected to the WordPress initial setup page like the image shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/wordpress-setup.png\" alt=\"WordPress initial setup page\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to make changes to the configuration, simply update the files and run the <em>docker-compose<\/em>&nbsp;command again.&nbsp;If docker-compose detects&nbsp;the configuration or the image has&nbsp;changed since&nbsp;the container was created, it applies&nbsp;the changes by stopping and recreating the containers while preserving mounted volumes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, you can check for updates on the WordPress and MariaDB&nbsp;images and push changes to your containers using the commands below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker-compose pull\ndocker-compose up -d<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Other useful commands for docker-compose are start\/stop, config, ps and down.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Starts all stopped containers in the work directory\ndocker-compose start\n# Stops all currently running containers in the work directory\ndocker-compose stop\n# Validates and shows the configuration\ndocker-compose config\n# Lists all running containers in the work directory\ndocker-compose ps\n# Stops and removes all containers in the work directory\ndocker-compose down<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Docker-compose also has its own command-line reference guide at the&nbsp;<a href=\"https:\/\/docs.docker.com\/compose\/reference\/overview\/\" target=\"_blank\" rel=\"noopener\">documentation page<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Congratulations, you should now have a docker-compose set-up with WordPress and MariaDB running in containers and an easy way to update the services when needed. While manually running Docker commands to create containers already simplifies application management, docker-compose takes it a step further and allows you to bundle multiple containers within a single working directory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before continuing on building your new WordPress site, make sure to pay attention to the security on your server. To find out more, check out our article on <a href=\"https:\/\/upcloud.com\/global\/resources\/tutorials\/secure-linux-cloud-server\/\">how to secure your Linux cloud server<\/a>.<\/p>\n","protected":false},"author":3,"featured_media":27363,"comment_status":"open","ping_status":"closed","template":"","community-category":[241,277],"class_list":["post-2344","tutorial","type-tutorial","status-publish","has-post-thumbnail","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/types\/tutorial"}],"author":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/comments?post=2344"}],"version-history":[{"count":1,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2344\/revisions"}],"predecessor-version":[{"id":6427,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2344\/revisions\/6427"}],"wp:attachment":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/media?parent=2344"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/community-category?post=2344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}