skip to Main Content

I have a VPS setup with debian 10 and looking to add multiple wqordpress sites using docker compose. I am using nginx and letsencrypt in separate containers…and that part seems to be working. I get the SSL and can ping the site, WP wont connect to the database though and I have a feeling I am missing something simple…I’m a newb with docker and compose

here is my docker-compose.yml file

version: "3"

services:
   db_domain:
     image: mysql:5.7
     volumes:
        - db_data:/var/lib/mysql
     restart: always
     environment:
        MYSQL_ROOT_PASSWORD: Password1234
        MYSQL_DATABASE: domain-db
        MYSQL_USER: domainUser
        MYSQL_PASSWORD: otherPassword1234
     container_name: domain-db

   wordpress:
     depends_on:
        - db_domain
     image: wordpress:latest
     expose:
        - 80
     restart: always
     environment:
        VIRTUAL_HOST: domain.com
        LETSENCRYPT_HOST: domain.com
        LETSENCRYPT_EMAIL: [email protected]
        WORDPRESS_DB_HOST: db_domain:3306
        WORDPRESS_DB_USER: domainUser
        WORDPRESS_DB_PASSWORD: otherPassword1234
     container_name: domain-wp
volumes:
  db_data:

networks:
  default:
    external:
      name: nginx-proxy

2

Answers


  1. You have to add this WORDPRESS_DB_NAME: domain-db.

    And the WORDPRESS_DB_PASSWORD must to be equal to MYSQL_PASSWORD.

    Anyway, RTFM -> https://hub.docker.com/_/wordpress/

    Best regards.

    Login or Signup to reply.
  2. You have a couple of issues: The environment variables for the Mysql service are not setup properly and the WordPress service is missing the WORDPRESS_DB_NAME: domain-db environment variable.
    Here is a configuration that comes up without DB errors:

    version: "3"
    
    services:
       db_domain:
         image: mysql:5.7
         volumes:
            - db_data:/var/lib/mysql
         restart: always
         environment:
            - MYSQL_ROOT_PASSWORD=Password1234
            - MYSQL_DATABASE=domain-db
            - MYSQL_USER=domainUser
            - MYSQL_PASSWORD=otherPassword1234
         container_name: domain-db
         ports:
           - "3306:3306"
       wordpress:
         depends_on:
            - db_domain
         image: wordpress:latest
         expose:
            - 80
         restart: always
         environment:
            VIRTUAL_HOST: domain.com
            LETSENCRYPT_HOST: domain.com
            LETSENCRYPT_EMAIL: [email protected]
            WORDPRESS_DB_HOST: db_domain:3306
            WORDPRESS_DB_USER: domainUser
            WORDPRESS_DB_PASSWORD: otherPassword1234
            WORDPRESS_DB_NAME: domain-db
         container_name: domain-wp
    volumes:
      db_data:
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search