We need to create following docker compose file for Portainer. We will use
Maria DB as database
version: "3.8"
services:
database:
image: mariadb:10.6.4-focal
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- db-data:/var/lib/mysql
deploy:
resources:
limits:
memory: 2048m
phpmyadmin:
depends_on:
- database
image: phpmyadmin/phpmyadmin
ports:
- ${PUBLIC_PMA_PORT}:80
environment:
PMA_HOST: database
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
wordpress:
depends_on:
- database
image: wordpress:6.2.2-apache
ports:
- ${PUBLIC_WP_PORT}:80
environment:
WORDPRESS_DB_HOST: database:3306 # use the same name as database service
WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
WORDPRESS_DB_USER: ${MYSQL_USER}
WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- wp-content:/var/www/html/wp-content
volumes:
db-data:
wp-content:
And we need to provide the following variable details –
MYSQL_DATABASE=<YOUER_DB_NAME>
MYSQL_USER=<YOUER_DB_USER>
MYSQL_PASSWORD=<YOUER_DB_PASSWORD>
MYSQL_ROOT_PASSWORD=<YOUER_DB_ROOT_PASSWORD>
PUBLIC_WP_PORT=8080
PUBLIC_PMA_PORT=8081
Points to remember we are not exposing Database port. So database only accessible via phpMyAdmin and the WordPress site.