To set up and launch a WordPress site, we need to install both MySQL and WordPress. In this blog, I’ll be using Docker to facilitate the installation process. Docker provides a seamless and efficient way to bundle these components together, streamlining the setup and ensuring that our WordPress environment is both stable and portable. This approach not only simplifies the initial installation but also makes future management and updates more manageable.

Setting Up Docker

To easily install Docker, you have the option to use Docker Desktop. You can download the binary package installer suitable for your platform from Docker’s official documentation and proceed with the installation. If you’re working in an environment without GUI access and have only shell access, you can install Docker Engine by following the instructions available at Docker Engine Installation Guide. This allows for a straightforward setup process, whether you prefer a graphical interface or a command-line approach.

Perquisites and Assumptions

  • Before proceeding with the setup, ensure that the domain name you plan to use is correctly pointing to your server IP. For instance, if your server IP is 1.2.3.4 and your domain name is example.com, then example.com should be directed to 1.2.3.4.
  • It’s also crucial to verify that no other applications or processes are running on port 80, as WordPress has been configured to run on this port. If port 80 is occupied, you can switch to an alternative port such as 8080 or 9090. Detailed instructions for changing the port can be found in the “Install WordPress” section of this guide.
  • Additionally, you’ll need to create a Docker network to facilitate communication between the MySQL and WordPress containers. To set up a Docker network named wp_network, simply run the command: docker network create wp_network. This network will enable both containers to interact seamlessly.

Installing MySQL: The Essential Steps

Next, we will install MySQL using Docker. You can deploy the MySQL container with the following command:
docker run --name wp-mysql --network wp_network -e MYSQL_ROOT_PASSWORD=password -d mysql:8
This command sets up a MySQL 8 Docker container and connects it to the wp_network. For additional details or alternative configurations, you can refer to the official MySQL Docker documentation available at Docker Hub MySQL.

Install WordPress: Using Docker

Continuing with our setup, the next step is to install WordPress using Docker. Execute the following command to deploy a WordPress container, ensuring it connects to the same Docker network as our MySQL container:
docker run --name wordpress --network wp_network -e WORDPRESS_DB_HOST=wp-mysql -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD=password -p 80:80 -d wordpress
This command creates a WordPress container named wordpress, which will connect to the MySQL container wp-mysql over the wp_network. It sets the WordPress database host, user, and password, and maps port 80 on your host to port 80 in the container, allowing you to access WordPress through your server’s IP address.
For more detailed information on configuring and customizing your WordPress Docker setup, please consult the official WordPress Docker documentation at Docker Hub WordPress. This resource provides extensive guidance on various WordPress configurations and usage scenarios.

If you have another application, such as Nginx, running on port 80, you will need to modify the port mapping to avoid conflicts. Change -p 80:80 to -p 8080:80 in your Docker command. This alteration binds port 80 on the container to port 8080 on your host machine, allowing both applications to run simultaneously without interfering with each other.

Using Docker Compose to Install MySQL and WordPress Together

You can skip this step if you have already followed the previous instructions. In this step, we will streamline the process by using Docker Compose to create a Docker network, install MySQL, and install WordPress all in one go. This method is ideal for deployment, as it requires minimal commands and consolidates all configurations into a single file, making the setup process simpler and more efficient.


To streamline the deployment process of WordPress and MySQL using Docker, Docker Compose or Docker Stack Deploy is an excellent tool that allows you to define and run multi-container Docker applications. Below, I’ll guide you through setting up a stack.yml file based on the instructions from Docker Hub WordPress, and then deploying it.

version: '3.7'  # Ensure compatibility with Docker Stack

services:
  wordpress:
    image: wordpress:latest
    restart: always
    ports:
      - "80:80"
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - wordpress_data:/var/www/html
    networks:
      - webnet

  db:
    image: mysql:8
    restart: always
    environment:
      MYSQL_DATABASE: exampledb
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      MYSQL_ROOT_PASSWORD: somerootpassword
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - webnet

networks:
  webnet:

volumes:
  wordpress_data:
  db_data:

Navigate to the directory containing your stack.yml. Use the following commands to deploy your services using Docker Stack, assuming you have Docker Swarm initialized on your server:

docker stack deploy -c stack.yml wpstack

Accessing WordPress

Once the containers are running, you can access your WordPress site by navigating to http://localhost or http://<your-server-ip> or http://<your domain.com> in your web browser. If you are using a different port (for instance, if you changed “80:80” to “8080:80”), adjust the URL accordingly (e.g., http://localhost:8080).

This setup ensures that you have a fully functional WordPress installation running through Docker.

Configuring SSL for Secure Connections

An upcoming post will cover setting up SSL using Nginx, Certbot, and Let’s Encrypt. Stay tuned for the publication!

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *