I am attempting to set up a Docker environment with two WordPress instances, each connecting to a shared MySQL database. The configuration I want has one WordPress running on port 8000 and the other on port 8001.
Here is the docker-compose setup I’m trying:
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: yourpassword
MYSQL_DATABASE: wordpress_db
MYSQL_USER: wordpress_user
MYSQL_PASSWORD: wordpress_pass
wordpress-first:
depends_on:
- db
image: wordpress:latest
container_name: first-blog
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress_user
WORDPRESS_DB_PASSWORD: wordpress_pass
WORDPRESS_TABLE_PREFIX: first_
wordpress-second:
depends_on:
- db
image: wordpress:latest
container_name: second-blog
ports:
- "8001:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress_user
WORDPRESS_DB_PASSWORD: wordpress_pass
WORDPRESS_TABLE_PREFIX: second_
volumes:
db_data:
After executing docker-compose up, everything seems to work well, and the following services are visible:
STATUS PORTS NAMES
Up 10 minutes 0.0.0.0:8000->80/tcp first-blog
Up 10 minutes 0.0.0.0:8001->80/tcp second-blog
Up 10 minutes 3306/tcp wordpress_db
However, when I try to access localhost:8001, it redirects to localhost:8000, giving me an HTTP 301 status. I suspect this might be a WordPress issue, but I’m uncertain. Can anyone help me understand why this is happening?