首页 > 解决方案 > magento2 error on Docker: There are no commands defined in the "setup" namespace

问题描述

I'm installing magento2 in a Docker container with OS as below.

Linux 8791be8c3c43 5.0.0-23-generic #24~18.04.1-Ubuntu SMP Mon Jul 29 16:12:28 UTC 2019 x86_64 GNU/Linux

When I try to setup magento with the command and parameters below, I get the error:

There are no commands defined in the "setup" namespace.

bin/magento setup:install \
--base-url=http://localhost/magento2 \
--db-host=localhost \
--db-name=magento \
--db-user=magento \
--db-password=magento \
--backend-frontname=admin \
--admin-firstname=admin \
--admin-lastname=admin \
--admin-email=admin@admin.com \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1

As per some post I've found I ran this command below, it seems that it displays issues in the magento setup. The last error, the one making reference to SODIUM I solved by installing sodium extension. The others seems to be solved too.

enter image description here

magento@8791be8c3c43:/var/www/html/magento2$ php bin/magento list
Magento CLI 2.3.2

In ServiceManager.php line 1130:

  An abstract factory could not create an instance of magentosetupconsolecommandbackupcommand(alias: Magento\Setup\Console\Command\BackupCommand).  


In ServiceManager.php line 941:

  An exception was raised while creating "Magento\Setup\Console\Command\BackupCommand"; no instance returned  


In Di.php line 865:

  Missing instance/object for parameter maintenanceMode for Magento\Setup\Console\Command\BackupCommand::__construct  


In ServiceManager.php line 1130:

  An abstract factory could not create an instance of magentoframeworkappmaintenancemode(alias: Magento\Framework\App\MaintenanceMode).  


In ServiceManager.php line 941:

  An exception was raised while creating "Magento\Framework\App\MaintenanceMode"; no instance returned  


In ErrorHandler.php line 61:

  Warning: Use of undefined constant SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13 - assumed 'SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13' (this will throw an Error in a future version of PHP) in /var/www/html/magento2/  
  lib/internal/Magento/Framework/Encryption/Encryptor.php on line 153 

I tried to solve the issue by following some steps I've found in some post, like removing the content of the directories below, then trying to execute php bin/magento cache:flush and php bin/magento setup:upgrade but anything I try to run starting with php bin/magento... gets me the error: There are no commands defined in the "xxxxxx" namespace.

rm -Rf var/cache/*
rm -Rf var/generation/*

Some solutions I found were based on fixing permissions folder issues, but I believe I have no permission issues, as my "magento" user is member of owner group of installation folder (see my code below), and composer was installed with "magento" user and no errors were thrown.

# Create a new user and group, which will be Magento file system owner
useradd -m -U -r -d /opt/magento magento -s /bin/bash && \

# Add the magento user to the www-data group and change the /opt/magento directory permissions so that the Nginx can access the Magento installation:
usermod -a -G www-data magento && \
chmod 750 /opt/magento && \

wget https://github.com/magento/magento2/archive/2.3.2.tar.gz && \
tar -xzvf 2.3.2.tar.gz && \
chown -R www-data:www-data /var/www/html/magento2-2.3.2/ && \
chmod -R 775 /var/www/html/magento2-2.3.2/ && \
mv magento2-2.3.2/ magento2 && \
rm 2.3.2.tar.gz && \
cd magento2 && \
su magento && \

Any ideas to troubleshoot this issue are very welcome.

标签: phplinuxdockercontainersmagento2

解决方案


I ran into a similar issue, it was due to the libsodium version (1.0.11).

You can install an updated verison, see https://github.com/magento/magento2/issues/23405

Adding this to my docker file worked a charm:

RUN echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list 

RUN apt-get update && apt-get -t stretch-backports install -y libsodium-dev

RUN pecl install -f libsodium-1.0.17

推荐阅读