diff --git a/core/Command/Encryption/DecryptAll.php b/core/Command/Encryption/DecryptAll.php
index 9931a279ff4a72f2984f51c7e082d79d76ba63d0..253223f95295e1e31d49808fdea292d687566387 100644
--- a/core/Command/Encryption/DecryptAll.php
+++ b/core/Command/Encryption/DecryptAll.php
@@ -123,6 +123,14 @@ class DecryptAll extends Command {
 	}
 
 	protected function execute(InputInterface $input, OutputInterface $output) {
+		if ( !$input->isInteractive() ) {
+			$output->writeln('Invalid TTY.');
+			$output->writeln('If you are trying to execute the command in a Docker ');
+			$output->writeln("container, do not forget to execute 'docker exec' with");
+			$output->writeln("the '-i' and '-t' options.");
+			$output->writeln('');
+			return;
+		}
 
 		try {
 			if ($this->encryptionManager->isEnabled() === true) {
diff --git a/core/Command/Encryption/EncryptAll.php b/core/Command/Encryption/EncryptAll.php
index a2b566833249e0c5674c032b0aecc636b03532c8..b16fa0af2c780f239ed084d317006fa6dfb1279d 100644
--- a/core/Command/Encryption/EncryptAll.php
+++ b/core/Command/Encryption/EncryptAll.php
@@ -105,6 +105,14 @@ class EncryptAll extends Command {
 	}
 
 	protected function execute(InputInterface $input, OutputInterface $output) {
+		if ( !$input->isInteractive() ) {
+			$output->writeln('Invalid TTY.');
+			$output->writeln('If you are trying to execute the command in a Docker ');
+			$output->writeln("container, do not forget to execute 'docker exec' with");
+			$output->writeln("the '-i' and '-t' options.");
+			$output->writeln('');
+			return;
+		}
 
 		if ($this->encryptionManager->isEnabled() === false) {
 			throw new \Exception('Server side encryption is not enabled');
diff --git a/tests/Core/Command/Encryption/DecryptAllTest.php b/tests/Core/Command/Encryption/DecryptAllTest.php
index 1b01231ac57d29a30077d56d566d39dc99a17040..c85728640600122d39e2379bc75d7493f6aa456a 100644
--- a/tests/Core/Command/Encryption/DecryptAllTest.php
+++ b/tests/Core/Command/Encryption/DecryptAllTest.php
@@ -73,6 +73,9 @@ class DecryptAllTest extends TestCase {
 		$this->decryptAll = $this->getMockBuilder(\OC\Encryption\DecryptAll::class)
 			->disableOriginalConstructor()->getMock();
 		$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
+		$this->consoleInput->expects($this->any())
+			->method('isInteractive')
+			->willReturn(true);
 		$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
 
 		$this->config->expects($this->any())
diff --git a/tests/Core/Command/Encryption/EncryptAllTest.php b/tests/Core/Command/Encryption/EncryptAllTest.php
index 554560a35b71a3a8def2f0e69d863e01e42e123f..ca7b264c98ff8c2cf8df0ec487b1656473c4cd74 100644
--- a/tests/Core/Command/Encryption/EncryptAllTest.php
+++ b/tests/Core/Command/Encryption/EncryptAllTest.php
@@ -78,6 +78,9 @@ class EncryptAllTest extends TestCase {
 			->disableOriginalConstructor()
 			->getMock();
 		$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
+		$this->consoleInput->expects($this->any())
+			->method('isInteractive')
+			->willReturn(true);
 		$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
 
 	}