But suddenly, you find yourself needing to work with a WordPress setup
Software development
5 May 2025

But suddenly, you find yourself needing to work with a WordPress setup

There are times when you want nothing to do with it, you avoid it entirely. But suddenly, you find yourself needing to work with a WordPress setup that feels like a nightmare

There are times when you want nothing to do with it, you avoid it entirely. But suddenly, you find yourself needing to work with a WordPress setup that feels like a nightmare. You don’t even have PHP or MySQL installed, because all you wanted was to review the UI and make sure everything looked right in local development. That’s when Docker with MySQL and WordPress containers comes to the rescue.

Note: You are already using an existing MySQL container named my mysql, running on port 3306

Docker Network Setup

You created a shared Docker network so the WordPress container can connect to the MySQL container:

docker network create wp-network
docker network connect wp-network my-mysql

wp-config.php Configuration

You modified your wp-config.php with the correct database settings and updated the site URL to 127.0.0.1:8080:

define( 'DB_NAME',     'prosperanewsletter' );
define( 'DB_USER',     'root' );
define( 'DB_PASSWORD', 'MyS3cretPw' );
define( 'DB_HOST',     'my-mysql:3306' );

define( 'WP_HOME',     'http://127.0.0.1:8080' );
define( 'WP_SITEURL',  'http://127.0.0.1:8080' );

Final docker-compose.yml

services:
  wordpress:
    image: wordpress:latest
    container_name: wp_app
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - ./:/var/www/html
    networks:
      - wp-network

networks:
  wp-network:
    external: true

✅ It connects your WordPress container to your existing MySQL container via the shared wp-network.

Start WordPress

From your wordpress local folder, start the container:

docker-compose up -d

Then open the site in your browser:

http://127.0.0.1:8080

Restart / Stop

Restart WordPress container only:

docker-compose restart

Stop and remove WordPress container:

docker-compose down

So if you ever find yourself unexpectedly thrown into the WordPress chaos, don’t panic, spin up a Docker setup, review what you need, and keep your local machine clean. Minimal setup, maximum sanity.