For this installation, we need the following prerequisites:
Now, let's start the installation procedures:
mkdir docker -p && mkdir docker/wordpress -p && mkdir docker/wordpress/db -p && cd docker/wordpress
Use the below command to list open ports and if you are using the mentioned port in YAML file, you can change that in the below script:
sudo netstat -tulpn | grep LISTEN
nano docker-compose.yml
Or you can use the Portainer stack section as well.
Now you can paste the below script via the NANO editor if you want to use the Linux CLI, save and exit
version: '2.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8181:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- /root/docker/wordpress:/var/www/html
links:
- db:db
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- /root/docker/wordpress/db:/var/lib/mysql
volumes:
wordpress:
db:
Now you can start the container by using the below command or if you are using the Portainer please hit on that deploy button:
docker-compose up -d
So, after the creation of both needed containers you shouldn't go forward and do the WordPress mini setup using the IP address and port, and you should create the proxy host first in the Nginx proxy manager or any revers-proxy by using your domain or subdomain that you already allocated in the online DNS that you are using in your setup also you should get the needed SSL for that.
After all, since you have done all mentioned prerequisites, you can browse that FQDN address in your browser and start to finalize the Wordpress installation via the famous mini setup of Wordpress.
Also if you want to have another Wordpress instance on same server you can use the below YML:
version: '2.1'
services:
wordpress2:
image: wordpress
restart: always
ports:
- 8282:80
environment:
WORDPRESS_DB_HOST: db2
WORDPRESS_DB_USER: exampleuser2
WORDPRESS_DB_PASSWORD: examplepass2
WORDPRESS_DB_NAME: exampledb2
volumes:
- /root/docker/wordpress2:/var/www/html
links:
- db2:db2
db2:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb2
MYSQL_USER: exampleuser2
MYSQL_PASSWORD: examplepass2
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- /root/docker/wordpress2/db:/var/lib/mysql
volumes:
wordpress2:
db2:
Finally, if you want to know how to work with it, you can watch my related video.
Have fun…