Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Install WordPress on Docker (Windows, macOS, and Linux)
#1


How to Install WordPress on Docker (Windows, macOS, and Linux)



How to Deploy WordPress Image as a Docker Container


The following steps will show you how to install a WordPress content management system on a Docker container.


Step 1 – Install Docker


Docker is available for Windows, macOS, and Ubuntu. Here’s how you can install it on any of the three operating systems:


How to Install Docker on Ubuntu


In order to install Docker on a Linux VPS, you need to have a virtual private server (VPS) with one of the following operating systems:


Ubuntu Jammy 22.04 (LTS)
Ubuntu Impish 21.10
Ubuntu Focal 20.04 (LTS)
Ubuntu Bionic 18.04 (LTS)


Now, just follow the steps as shown:


Update the package list:
sudo apt-get update

Install the required packages:
sudo apt-get install ca-certificates curl gnupg lsb-release

Create a directory for the Docker GPG key:
sudo mkdir -p /etc/apt/keyrings

Add Docker’s GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Set up the repository:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Update Docker’s repository:
sudo apt-get update

Lastly, install the latest version of Docker Engine, containerd, and Docker Compose.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

To confirm that the installation process was successful, run the following command. The following success message should appear:
sudo docker run hello-world

Docker Hello World

How to Install Docker on macOS


In order to install Docker on a macOS machine, these requirements must be met:


  • 4 GB of RAM
  • macOS version 10.15 or newer
  • No previous versions of VirtualBox 4.3.30 can be installed

Here’s how you can install Docker on macOS:


  1. Download Docker for Mac and double-click the .dmg file you’ve saved. Then, drag and drop the Docker icon into your Applications folder.
  2. Open your Applications folder and double-click docker.app. During the configuration process, you’ll be asked to enter your password.
  3. When prompted, Accept the service agreement; otherwise, the installation will fail.
  4. Once the installation process is finished, you should see the Docker menu on your desktop’s status bar.
Docker macOS Installation

How to Install Docker on Windows


In order to install Docker Desktop on a Windows machine, these requirements must be met:


  • 4 GB of RAM
  • 64-bit processor from 2010 or more recent
  • Virtualization enabled in BIOS
  • Linux kernel update package installed if you are using the WSL 2 Docker back-end

Here’s how you can install Docker on Windows 10 64-bit:


  1. Enable Hyper-V on your system.
  2. Download Docker Desktop for Windows and open the Docker for Windows Installer file.
  3. In the Configuration dialog window, check the boxes based on your preferences. Click Ok.
  4. Once the installation is finished, click Close and restart and wait for your computer to reboot.
  5. After reboot, Accept the service agreement, and Docker will be ready to use.
Docker Windows Installation

Step 2 – Set Up WordPress Container on Docker


In order to set up WordPress on Docker, two methods are available ‒ the CLI and Docker compose. In this tutorial, we will use the Docker compose method as it’s more straightforward and systematic.


It’s worth noting that all required images are acquired from Docker Hub:


  • WordPress – the official WordPress Docker image. Includes all WordPress files, Apache server, and PHP.
  • MySQL – required for MySQL root user, password, and database connection variables.
  • phpMyAdmin – a web application for managing databases.

  1. Open your operating system’s preferred command line interface and check the Docker Compose Installation version:
    docker compose version
  2. Create a new project directory for WordPress application with the following command:
    mkdir wordpress
  3. Navigate to the new directory:
    cd wordpress
  4. Using your preferred text editor, create a new docker-compose.yml file, and paste the contents below:

version: "3"
services:
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: MyR00tMySQLPa$$5w0rD
      MYSQL_DATABASE: MyWordPressDatabaseName
      MYSQL_USER: MyWordPressUser
      MYSQL_PASSWORD: Pa$$5w0rD

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    restart: always
    ports:
      - "8000:80"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: MyWordPressUser
      WORDPRESS_DB_PASSWORD: Pa$$5w0rD
      WORDPRESS_DB_NAME: MyWordPressDatabaseName

    volumes:
      - "./:/var/www/html"

volumes:
  mysql: {}

  1. With the Docker Compose file created, run the following command in the same wordpress directory to create and start the containers:
    docker compose up -d

Step 3 – Complete WordPress Installation on a Web Browser


Open your browser and enter http://localhost:8000/. The WordPress setup screen will appear. Select the preferred language and continue.


WordPress Setup Screen

Fill in your site name, username, password, and email.


WordPress Installation Details

When a Success! message pops-up, log in using your newly created details.


WordPress Login

Lastly, you’ll be presented with the main WordPress dashboard screen.


Setting up phpMyAdmin


phpMyAdmin is a great tool for viewing and managing any existing databases. All you need to do is include these lines to an existing .yml file just after the services line along with the MySQL database service:



version: "3"
services:
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: MyR00tMySQLPa$$5w0rD
      MYSQL_DATABASE: MyWordPressDatabaseName
      MYSQL_USER: MyWordPressUser
      MYSQL_PASSWORD: Pa$$5w0rD

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    restart: always
    environment:
      PMA_HOST: db
      PMA_USER: MyWordPressUser
      PMA_PASSWORD: Pa$$5w0rD
    ports:
      - "8080:80"

Save the file and run the docker-compose Docker command:
docker compose up -d


Once done, open http://localhost:8080/, and you’ll be able to see the phpMyAdmin interface along with your WordPress database.


phpMyAdmin Interface





Reply


Messages In This Thread
How to Install WordPress on Docker (Windows, macOS, and Linux) - by aaron - 08-12-2023, 10:20 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)