craftcms / docker

Craft CMS Docker images.
104 stars 38 forks source link

Database dump with just base image doesn't work #50

Open noahjahn opened 3 years ago

noahjahn commented 3 years ago

Description

The database dump functionality when using a postgres database no longer works. It looks like the postgres client was just removed from the image Since the database dump from the control panel requires the postgres client to be installed, does it make sense to keep that dependency in the image?

Steps to reproduce

  1. Create a new craft project: https://craftcms.com/docs/3.x/installation.html
  2. Update the .env file with the following credentials:
    DB_DRIVER=pgsql
    DB_SERVER=host.docker.internal
    DB_PORT=5432
    DB_DATABASE=craft
    DB_USER=craft
    DB_PASSWORD=secret
    DB_SCHEMA=public
    DB_TABLE_PREFIX=
  3. Start a PostgreSQL database: docker run --rm --env POSTGRES_USER=craft --env POSTGRES_PASSWORD=secret -d -p 5432:5432 postgres:13
  4. From within the project directory, start the web server in the Craft docker image: docker run --rm -d -v "$(pwd):/app" -p 80:8080 craftcms/nginx:8.0
  5. In your browser, follow through the install steps: http://localhost/index.php?p=admin/install
  6. Login with the account you just created
  7. In Utilities > Database Backup, click Backup
  8. See error!
2021-11-08 11:15:52 [-][1][fa3bd882bbbcddbef1853ef1b38cadb3][error][yii\base\Exception] yii\base\Exception: Could not create backup: The shell command "PGPASSWORD="••••••" pg_dump --dbname=craft --host=host.docker.internal --port=5432 --username=craft --if-exists --clean --no-owner --no-privileges --no-acl --file="/app/storage/backups/test--2021-11-08-191552--v3.7.20.sql" --schema=public --column-inserts --exclude-table-data 'public.assetindexdata' --exclude-table-data 'public.assettransformindex' --exclude-table-data 'public.sessions' --exclude-table-data 'public.templatecaches' --exclude-table-data 'public.templatecachequeries' --exclude-table-data 'public.templatecacheelements' --exclude-table-data 'public.cache' --exclude-table-data 'public.templatecachecriteria'" failed with exit code 127: sh: pg_dump: not found in /app/vendor/craftcms/cms/src/controllers/UtilitiesController.php:346
Stack trace:
#0 [internal function]: craft\controllers\UtilitiesController->actionDbBackupPerformAction()
#1 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#2 /app/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#3 /app/vendor/yiisoft/yii2/base/Module.php(534): yii\base\Controller->runAction('db-backup-perfo...', Array)
#4 /app/vendor/craftcms/cms/src/web/Application.php(287): yii\base\Module->runAction('utilities/db-ba...', Array)
#5 /app/vendor/craftcms/cms/src/web/Application.php(596): craft\web\Application->runAction('utilities/db-ba...', Array)
#6 /app/vendor/craftcms/cms/src/web/Application.php(266): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#7 /app/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))
#8 /app/web/index.php(26): yii\base\Application->run()
#9 {main}

Additional info

noahjahn commented 3 years ago

A workaround is to just add the postgresql-client in a Dockerfile pulling from the Craft image:

FROM craftcms/nginx:8.0

USER root

RUN apk --no-cache add postgresql-client && \

USER www-data