WordPress is arguably the most widely used free and open-source CMS around the world and is not really going anywhere. About 43% of the global web is built on WordPress by bloggers, small businesses, and many other companies. If you are looking to build your own WordPress website and looking to host it on your own cloud instance or computer then this tutorial is just for you. Today we are covering how to set up and self-host WordPress with docker.
Docker Compose And WordPress Setup
Like most of my tutorials, I generally like to make use of docker-compose and our very first step is to compile the docker-compose YAML and copy it to our self-host instance. Copy the YAML code below and edit where it is applicable to your environment.
docker-compose.yml
version: '2.1'
services:
wordpress:
depends_on:
- db
image: wordpress
container_name: wordpress-web
ports:
- "80:80"
restart: always
environment:
PUID: 1001
PGID: 1001
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress_pass
WORDPRESS_DB_NAME: wordpress
working_dir: /var/www/html
volumes:
- /docker/wordpress/wp-content:/var/www/html/wp-content
- /docker/wordpress/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
db:
image: ghcr.io/linuxserver/mariadb
container_name: wordpress-db
volumes:
- /docker/wordpress/db_data:/config
restart: always
environment:
- PUID=1001
- PGID=1001
- MYSQL_ROOT_PASSWORD=wordpress_pass
- TZ= #add your time zone here
- MYSQL_DATABASE=wordpress
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=wordpress_pass
Once logged in and copied to a directory within your docker host we can navigate to the directory with the Linux CLI and run docker-compose up -d
to deploy the WordPress containers. Once the docker-compose process is completed you can ensure that both containers are running with docker ps
and then open a browser tab and enter your docker host IP and it will take you to the install page below.
Once you entered all your website information and installed everything you will be redirected to the login screen ip_addr/wp-admin
where you can log in with the username and password you specified during the installation. From there you can modify your website and install and configure plugins within the WordPress dashboard.
Conclusion
In conclusion, WordPress is still the most widely used open-source cms and very much easy to use. If you enjoyed this article consider signing up for our newsletter and don't forget to share it with people that would find it helpful. Leave a comment below with a tutorial you would like us to cover.