WordPress install with Docker

Docker enables to separate your applications from your infrastructure so you can deliver software quickly.

This post aims to setup WordPress with Docker Compose. Why Docker Compose?

With Compose, you use a YAML file to configure your application’s services.

docker-compose.yaml or docker-compose.yml is file where services are defined. So, lets crack the nuts.

I am using Ubuntu.

First step: Install docker

  1. Update apt: sudo apt-get update
  2. Install required packages for docker. sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
  3. Add Docker’s official GPG key: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  4. Use the following command to set up the stable repository.
    echo \
    "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  5. Then, update again: sudo apt-get update
  6. Install docker: sudo apt-get install docker-ce docker-ce-cli containerd.io

Step 2: Install Docker compose

  1. Run this command to download the current stable release of Docker Compose using curl: sudo curl -L "https://github.com/docker/compose/releases/download/1.29.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  2. Apply executable permissions to the binary: sudo chmod +x /usr/local/bin/docker-compose

Step 3: Install WordPress container in Docker ship

  1. Make a directory for docker use. mkdir wp-docker
  2. Go to this directory. cd wp-docker
  3. Make a file named docker-compose.yml ( file extension can be .yml or .yaml ). touch docker-compose.yml
  4. Open docker-compose.yml in any editor and write the following code. Note that: YAML file is space sensitive.
version: "3.9"
    image: mysql:5.7
      - db_data:/var/lib/mysql
    restart: always
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    image: phpmyadmin
    restart: always
      - 8080:80
      - db
    image: wordpress:latest
      - "8000:80"
    restart: always
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes: ["./:/var/www/html"]
  db_data: {}

5. Run docker-compose up -d to run docker-compose file with detaching mode.
6. Go to localhost:8000 in the browser. Setup the famous WordPress installation.
7. Go to localhost:8080 in the browser. We have nothing to do with the server field. Enter user: wordpress and pass: wordpress. We found every data in wordpress database.

Leave a Reply

Your email address will not be published.