Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Docker Compose: WordPress + MySQL Using Shared Environment Variables

Create a project folder:

mkdir wordpress-env-demo
cd wordpress-env-demo

Create a .env file:

MYSQL_DATABASE=wordpressdb
MYSQL_USER=wpuser
MYSQL_PASSWORD=wppassword123
MYSQL_ROOT_PASSWORD=rootpassword123

WORDPRESS_PORT=8080

Create docker-compose.yml:

services:
  db:
    image: mysql:latest
    container_name: wordpress_mysql
    restart: always
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      - mysql_data:/var/lib/mysql

  wordpress:
    image: wordpress:latest
    container_name: wordpress_app
    restart: always
    depends_on:
      - db
    ports:
      - "${WORDPRESS_PORT}:80"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
      WORDPRESS_DB_USER: ${MYSQL_USER}
      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
    volumes:
      - wordpress_data:/var/www/html

volumes:
  mysql_data:
  wordpress_data:
Code language: JavaScript (javascript)

Start the containers:

docker compose up -d

Open WordPress:

http://localhost:8080
Code language: JavaScript (javascript)

Now students can see how environment variables are passed into both containers.

Check MySQL container env:

docker compose exec db printenv MYSQL_DATABASE
docker compose exec db printenv MYSQL_USER
docker compose exec db printenv MYSQL_PASSWORD

Check WordPress container env:

docker compose exec wordpress printenv WORDPRESS_DB_HOST
docker compose exec wordpress printenv WORDPRESS_DB_NAME
docker compose exec wordpress printenv WORDPRESS_DB_USER
docker compose exec wordpress printenv WORDPRESS_DB_PASSWORD

Verify both containers are using the same password:

docker compose exec db printenv MYSQL_PASSWORD
docker compose exec wordpress printenv WORDPRESS_DB_PASSWORD

Check how WordPress reads env and creates database config:

docker compose exec wordpress bash -lc 'grep DB_ /var/www/html/wp-config.php'
Code language: JavaScript (javascript)

Test MySQL login using the env variable inside DB container:

docker compose exec db bash -lc 'mysql -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE -e "SHOW TABLES;"'
Code language: JavaScript (javascript)

Check service-name networking between containers:

docker compose exec wordpress bash -lc 'getent hosts db'
Code language: JavaScript (javascript)

This works because Docker Compose creates an internal network where db becomes the hostname of the MySQL container.

Stop everything:

docker compose down

Stop and delete volumes also:

docker compose down -v

For teaching, this is perfect. For production, avoid latest, use fixed versions like wordpress:6.8-apache and mysql:8.4, and never commit real passwords into Git.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

OWASP Dependency-Check — 1-Hour Quick Demo Lab

Level: Beginner / Basic DevSecOpsDuration: 60 minutesFormat: Instructor-led hands-on demoFocus: Install → scan a real project → read findings → understand CVE/CVSS → generate reports → demonstrate a simple security gate…

Read More

OWASP Dependency-Check – Hands-On Lab Manual

OWASP Dependency-Check 13.0.0 Basic-to-Essentials Hands-On Lab Manual Audience: Beginners and engineers with basic DevOps/DevSecOps knowledgeTutorial verified/researched on: 2026-10-03OWASP Dependency-Check version: 13.0.0Minimum Java supported by Dependency-Check: Java 11Recommended lab Java runtime: Java 17…

Read More

Manufacturing automation: Is it worth investing in the field of manufacturing automation?

An investment in manufacturing automation can pay off. (Photo: Generated with the help of AI) Manufacturing automation has developed from a solution mainly associated with large factories…

Read More

How to Choose a Virtual Machine for Development and Production Workloads

Virtual machines remain a practical building block for development, testing, staging, production services, and infrastructure automation. The challenge is not simply choosing the largest instance available. It…

Read More

System Mechanic vs Advanced SystemCare for Small Teams Without an MDM

If you’re keeping a handful of Windows workstations or test machines healthy without a device-management platform, iolo’s System Mechanic is the better choice over IObit’s Advanced SystemCare…

Read More

How to Plan Infrastructure for a Community Project

Every thriving community project sits on top of infrastructure nobody notices, right up until it breaks. The forum. The server. The backups. The dull plumbing that holds…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x