Reputation: 103
I built two WordPress websites, one bound to port 9000
and one to 8000
. They are both connected to the same MySQL database.
When I access the port 8000
it works perfectly and connects to both the website and the database.
On the other side, when I access the port 9000
it just automatically redirects me to the port 8000
and to its website. Any reason why this may happen?
This is the docker-compose
file:
Tried to clear the cache and tried it on Firefox (default browser is Chrome) but it still happens.
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
second_wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "9000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
Upvotes: 2
Views: 1133
Reputation: 103
The problem was that both sites used the same DATABASE inside mySQL, the solution was to create different databases in mySQL and assign each website to it.
Then the wordpress sites will take the info from different databases and not route.
Upvotes: 1
Reputation: 25189
Go to http://localhost:9000/wp-admin/install.php to install your second instance.
Be aware that the configuration is stored in files (in /var/www/html/) inside the container and will be lost when you stop the container. So you'll have to install it again when you restart.
If you want to save the configuration, you can create a volume and map it to /var/www/html using something like this
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
- wordpress:/var/www/html
and
volumes:
wordpress:
Upvotes: 1