diff --git a/examples/compose-wordpress-mysql/README.md b/examples/compose-wordpress-mysql/README.md new file mode 100644 index 0000000..87cee4d --- /dev/null +++ b/examples/compose-wordpress-mysql/README.md @@ -0,0 +1,86 @@ +## šŸŒŸ WordPress Wonderland with MySQL šŸŒˆ + +Embark on an exhilarating journey into the WordPress Wonderland, now powered by the enchanting MariaDB! šŸš€ This example brings to life a captivating WordPress setup, with a dash of magic from MariaDB. Feel free to swap the enchantment to MySQL by simply unraveling a line in the mystical `compose.yaml` file. + +### āœØ Project Structure + +```plaintext +. +ā”œā”€ā”€ compose.yml # šŸŒ Docker Compose configuration orchestrating the WordPress magic. +ā”œā”€ā”€ .env # šŸ—ļø Environment file holding configuration secrets for MySQL/MariaDB. +ā”œā”€ā”€ nginx/ # šŸŒ Nginx configuration directory, shaping the entrance to the WordPress realm. +ā”‚ ā””ā”€ default.conf # šŸ–Œļø Custom Nginx configuration, optimizing the front-end experience. +ā”œā”€ā”€ wordpress/ # šŸŒ WordPress configuration directory, defining the ambiance of the digital space. +ā”‚ ā””ā”€ 000-default.conf # šŸ–Œļø Tailored WordPress configuration for a rich and engaging content experience. +ā”œā”€ā”€ db/ # šŸŒ MySQL/MariaDB initialization script directory, setting the stage for database marvels. +ā”‚ ā””ā”€ init.sql # šŸ–Œļø MySQL/MariaDB initialization script, creating the enchanted database realm. +``` + +### šŸŽ­ `compose.yml` - The Magic Potion + +```yaml +version: '3' + +services: + nginx: + image: nginx:alpine3.18-slim + ports: + - "80:80" + ... + wordpress: + image: wordpress:latest + restart: always + ... + db: + # šŸ§™ā€ā™€ļø MariaDB image supporting both amd64 & arm64 architecture + image: mariadb:11.0.3 + # šŸ§™ā€ā™‚ļø If you fancy MySQL, just uncomment the line below + # image: mysql:8.1.0 + ... +``` + +### šŸš€ Deploy with Docker Spells + +```bash +docker-compose up -d +``` + +Watch in awe as a network and a magical volume come to life, deploying the enchanted containers... + +```bash +āœ” Network compose-wordpress-mysql_default Created 0.0s +āœ” Volume "compose-wordpress-mysql_db-data" Created 0.0s +āœ” Container compose-wordpress-mysql-db-1 Started 0.0s +āœ” Container compose-wordpress-mysql-wordpress-1 Started 0.0s +āœ” Container compose-wordpress-mysql-nginx-1 Started 0.1s +``` + +### āœØ Expected Spellbinding Result + +Peer into the mystic realm and inspect the port mapping: + +```bash +$ docker-compose ps +NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS +compose-wordpress-mysql-db-1 mariadb:11.0.3 "docker-entrypoint.sā€¦" db About a minute ago Up About a minute 3306/tcp +compose-wordpress-mysql-nginx-1 nginx:alpine3.18-slim "/docker-entrypoint.ā€¦" nginx About a minute ago Up About a minute 0.0.0.0:80->80/tcp, :::80->80/tcp +compose-wordpress-mysql-wordpress-1 wordpress:6.3.1-php8.2 "docker-entrypoint.sā€¦" wordpress About a minute ago Up About a minute 80/tcp +``` + +Take a magic carpet ride to `http://localhost:80` in your web browser to witness the enchanting WordPress realm. + +![WordPress](./output.jpg) + +### šŸ›‘ Stop the Magic, Remove the Spellbound Containers + +```bash +docker-compose down +``` + +To erase all traces of the enchanted WordPress data, including the named volumes: + +```bash +docker-compose down -v +``` + +Your WordPress Wonderland with MariaDB or MySQL is now ready for you to shape and mold as you please. šŸŒŸ Let the creativity soar, and may your digital adventures be as boundless as the stars! šŸŒŒ diff --git a/examples/compose-wordpress-mysql/compose.yml b/examples/compose-wordpress-mysql/compose.yml new file mode 100644 index 0000000..9152fe5 --- /dev/null +++ b/examples/compose-wordpress-mysql/compose.yml @@ -0,0 +1,36 @@ +version: '3' + +services: + nginx: + image: nginx:alpine3.18-slim + depends_on: + - wordpress + ports: + - "80:80" + volumes: + - ./nginx:/etc/nginx/conf.d + + wordpress: + image: wordpress:6.3.1-php8.2 + restart: always + environment: + WORDPRESS_DB_HOST: db + WORDPRESS_DB_USER: root + WORDPRESS_DB_PASSWORD: example + WORDPRESS_DB_NAME: wordpress + volumes: + - ./wordpress:/var/www/html + depends_on: + - db + + db: + image: mariadb:11.0.3 + environment: + MARIADB_ROOT_PASSWORD: example + MARIADB_DATABASE: wordpress + volumes: + - db-data:/var/lib/mysql + - ./db:/docker-entrypoint-initdb.d + +volumes: + db-data: diff --git a/examples/compose-wordpress-mysql/db/init.sql b/examples/compose-wordpress-mysql/db/init.sql new file mode 100644 index 0000000..ac472be --- /dev/null +++ b/examples/compose-wordpress-mysql/db/init.sql @@ -0,0 +1,5 @@ +CREATE DATABASE IF NOT EXISTS wordpress; +USE wordpress; + +GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'example' WITH GRANT OPTION; +FLUSH PRIVILEGES; diff --git a/examples/compose-wordpress-mysql/nginx/default.conf b/examples/compose-wordpress-mysql/nginx/default.conf new file mode 100644 index 0000000..0993411 --- /dev/null +++ b/examples/compose-wordpress-mysql/nginx/default.conf @@ -0,0 +1,16 @@ +# nginx/default.conf +server { + listen 80; + server_name localhost; + + location / { + proxy_pass http://wordpress:80; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; +} diff --git a/examples/compose-wordpress-mysql/output.jpg b/examples/compose-wordpress-mysql/output.jpg new file mode 100644 index 0000000..5d03933 Binary files /dev/null and b/examples/compose-wordpress-mysql/output.jpg differ diff --git a/examples/compose-wordpress-mysql/wordpress/000-default.conf b/examples/compose-wordpress-mysql/wordpress/000-default.conf new file mode 100644 index 0000000..8bb1dfe --- /dev/null +++ b/examples/compose-wordpress-mysql/wordpress/000-default.conf @@ -0,0 +1,7 @@ + + ServerAdmin webmaster@localhost + DocumentRoot /var/www/html + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined +