urbantrout / craftcms

Craft CMS Docker Image
MIT License
76 stars 32 forks source link

Failed to install plugins - Can't connect to the database #15

Closed Elindalyne closed 3 years ago

Elindalyne commented 4 years ago

When running on a new server I'm getting the following error after packages install via composer

craft_1 | 14 packages you are using are looking for funding. craft_1 | Use the ``composer fund`` command to find out more! craft_1 | ==> ✅ All dependencies successfully installed. craft_1 | ==> Activating Plugins. craft_1 | *** installing redactor-custom-styles craft_1 | *** failed to install redactor-custom-styles: Craft CMS can’t connect to the database with the credentials in config/db.php. I know for a fact that the database is indeed running since I can connect to it via mysqlworkbench.

I'm not a linux gal normally so I'm betting this is a permissions issue, I just don't know how to fix it.

Here's my docker-compose file in case that helps


version: '2.1'

services:
  nginx:
    image: nginx:alpine
    ports:
      - 80:80
    depends_on:
      - craft
    volumes_from:
      - craft
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf # nginx configuration (see below)
      - ./assets:/var/www/html/web/assets # For static assets (media, js and css).

  craft:
    image: urbantrout/craftcms:mysql # Use mysql instead of postgresql
    depends_on:
      - mariadb
    volumes:
      - ./assets:/var/www/html/web/assets:z
      - ./backups:/var/www/html/storage/backups # Used for db restore on start.
      - ./templates:/var/www/html/templates # Craft CMS template files
      - ./translations:/var/www/html/translations
      - ./redactor:/var/www/html/config/redactor
      - ./contact-form.php:/var/www/html/config/contact-form.php

    environment:
      DEPENDENCIES: >- # additional composer packages
        yiisoft/yii2-redis
        craftcms/redactor:2.6.0.1
        craftcms/contact-form
        carlcs/craft-redactorcustomstyles
        ether/seo

      CRAFTCMS_EMAIL:xxx
      CRAFTCMS_USERNAME: xxx
      CRAFTCMS_PASSWORD: xxx
      CRAFTCMS_SITENAME: xxx
      #CRAFTCMS_SITEURL: http://dev.project.com # Optional

      AUTO_UPDATE: 'true' # Enable/disable auto updates for all composer packages (including Craft CMS, Default: true)

      REDIS_HOST: redis
      SESSION_DRIVER: redis
      CACHE_DRIVER: redis

      DB_SERVER: mariadb
      DB_NAME: craft
      DB_USER: craft
      DB_PASSWORD: xxx
      DB_DATABASE: craft
      DB_SCHEMA: public
      DB_DRIVER: mysql
      DB_PORT: 3306
      DB_TABLE_PREFIX: ut

  mariadb:
    image: mariadb:10.1
    environment:
      MYSQL_ROOT_PASSWORD: xxx
      MYSQL_USER: craft
      MYSQL_PASSWORD: xxx
      MYSQL_DATABASE: craft
    volumes:
      # Persistent data
      - dbdata:/var/lib/mysql
    ports:
      -  3306:3306

  redis:
    image: redis:4-alpine
    volumes:
      - redisdata:/data

volumes:
  dbdata:
  redisdata:`
mrhubbs commented 4 years ago

I'm having the same issue with a similar configuration. I last tried this in April and wasn't having a problem.

mrhubbs commented 4 years ago

@Elindalyne I just looked back through the history and saw the DB_DSN env var was added to the README 4 months ago. Here's a snippet:


      DB_DSN: mysql:host=mariadb;dbname=craft
      DB_SERVER: mariadb
      DB_NAME: craft
      DB_USER: craft

That solved the problem for me.