Cloud & containers

Deploy your WordPress site with Docker on Linux

Install Docker and docker-compose on Linux, write a docker-compose.yml file pairing WordPress with MariaDB, start the containers and run the first setup.

· 2 min read · level: intermediate · on docker-compose 1.29.2

Installing Docker

curl -fsSL https://get.docker.com/ | sh

Adding a user to the docker group in order to run the docker command

sudo usermod -aG docker username

Installing docker-compose

sudo curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

Adding execution rights on docker-compose

sudo chmod +x /usr/local/bin/docker-compose
Illustration 1 — Déployez votre site Wordpress avec Docker sur Linux

Creating a directory for our wordpress project

sudo mkdir /srv/wordpress
cd /srv/wordpress

Creating the docker-compose.yml

sudo nano docker-compose.yml
wordpress:
    image: wordpress
    links:
     - mariadb:mysql
    environment:
     - WORDPRESS_DB_PASSWORD=changecomplexpassword777%
     - WORDPRESS_DB_USER=root
    ports:
     - "80:80"
    volumes:
     - ./html:/var/www/html
mariadb:
    image: mariadb
    environment:
     - MYSQL_ROOT_PASSWORD=changecomplexpassword777%
     - MYSQL_DATABASE=wordpress
    volumes:
     - ./database:/var/lib/mysql

Running the container and keeping it online

docker-compose up -d

Checking the state of the docker processes

docker ps

Using the IP address of the Linux server and the port number associated with the web service, we can now connect from a browser.

Illustration 2 — Déployez votre site Wordpress avec Docker sur Linux

Choose the language in which WordPress will be displayed.

Illustration 3 — Déployez votre site Wordpress avec Docker sur Linux

Save this password in a password manager right now.

Illustration 4 — Déployez votre site Wordpress avec Docker sur Linux