evertramos / docker-wordpress

Wordpress Docker container using SSL Certificates with LetsEncrypt
https://evertramos.github.io/docker-wordpress/
MIT License
484 stars 156 forks source link

Problems creating a second WordPress install with a shared database #36

Closed avidsapp closed 5 years ago

avidsapp commented 5 years ago

I have successfully set up separate WordPress installs without changing the service names in the docker-compose.yml as referenced by #24, but rather installing in subdomains with different container names for WP and the db and housing the sites in separate directories. This spins up separate db containers. Now I want to be able to share an already running database container, but create a new WP container. How can I accomplish this?

version: '3'
services:
   db:
     container_name: ${CONTAINER_DB_NAME}
     image: mariadb:latest
     restart: unless-stopped
     volumes:
        - ${DB_PATH}:/var/lib/mysql
     environment:
       MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
       MYSQL_DATABASE: ${MYSQL_DATABASE}
       MYSQL_USER: ${MYSQL_USER}
       MYSQL_PASSWORD: ${MYSQL_PASSWORD}
     external_links:
        - sitename-db
...

with .env showing:

...

# Path to store your database
#DB_PATH=/path/to/your/local/database/folder
DB_PATH=../sitename/data

...

outputs

ERROR: for sitename-db  Cannot create container for service db: Conflict. The container name "/sitename-db" is already in use by container "13rjbwdv98wdvb2...". You have to remove (or rename) that container to be able to reuse that name.

After connecting to a shared database, I can edit the WP install itself.

evertramos commented 5 years ago

Hello @avidsapp,

Try the following:

  1. remove the db service and dependecy from the composer example

  2. rename the service for the cotnainer

  3. put this container new wp container in the same network of the db you want to connect

  4. set the access details

  5. change the database name or prefix

and fire it up!

It should work like a charm!

avidsapp commented 5 years ago

Hi @evertramos. Thanks for the walkthrough. I have actually decided to do a multisite instead, but may return to this if needed.