Install WordPress Using Docker

2023-07-10

Installing WordPress on a server is a terrible thing, especially if you are not familiar with php and don’t know much about databases. If there were some troubles in process, there may be a lot of junk files remaining. So using docker to install wordpress is a good choice.

Prepare

One ubuntu server, other linux systems are roughly the same;

A docker compose configuration file;

An uploads.ini configuration file

install docker

First, run the following command to uninstall all conflicting packages:

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

Update the apt package index and install packages to allow apt to use a repository over HTTPS:

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg

Add Docker’s official GPG key:

 sudo install -m 0755 -d /etc/apt/keyrings
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
 sudo chmod a+r /etc/apt/keyrings/docker.gpg

Set up the repository with the following command:

echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Update  apt the package index again:

sudo apt-get update

Install the latest Docker engine, containerd and Docker Compose.

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

take a try:

sudo docker run hello-world

If the following is displayed, it means success.

Hello from Docker!
This message shows that your installation appears to be working correctly.

install wordpress

mkdir a directory and enter the folder

mkdir docker-wp && cd docker-wp
vim docker-compose.yaml

Prepare a docker compose configuration file

version: "3"
  
services:
  db:
    image: mysql/mysql-server
    command: mysqld --max_allowed_packet=20M
    volumes:
      - ./mysql:/var/lib/mysql
    ports:
        - "13306:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: changeyourpassword
      MYSQL_DATABASE: itc_wp
      MYSQL_USER: itc_user
      MYSQL_PASSWORD: changeyourpassword
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
        - ./config/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
        - ./html:/var/www/html
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: itc_user
      WORDPRESS_DB_PASSWORD: changeyourpassword
      WORDPRESS_DB_NAME: itc_wp

Create a new config directory, enter the directory to create an uploads.ini file

sudo mkdir config && cd config
vim upload.ini
file_uploads = On
memory_limit = 1024M
upload_max_filesize = 2048M #可以上传2g的文件,如视频
post_max_size = 2048M
max_execution_time = 600

Now, go back to the docker-wp directory (the directory where docker-compose.yaml is located), ready to start docker compose.

docker compose up -d

Ok, now visit http://yourip:8000, you can see the settings page of wordpress.

©2024ye-yu.com All Rights Reserved.