cURL requests error 7 while trying a HTTP POST request to localhost from the app


I am trying to make a cURL request from an app i am developing to localhost but each HTTP request i make returns a cURL error 7. Same problem while trying with the iClient’s post method. I tried whitelisting the HTTP request’s target URL but it does not seem to fix the issue. Is there a firewall preventing cURL requests from being fired ?

I am running Nextcloud in a docker container.

My cURL function :

public function testConnection(string $UserId) {
        $completeConfig = $this->completeConfig($UserId);
        $iClient = $this->IClientService->newClient();
        try {
            $ch    = curl_init();
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_URL, "http://localhost:8000/plugin");
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $completeConfig);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            $response = curl_exec($ch);
            if($response === false){
                throw new Exception(curl_error($ch), curl_errno($ch));
            return $response;
        catch(Exception $e) {
            trigger_error(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR);
        finally {


My current config.php:

$CONFIG = array(
    'htaccess.RewriteBase' => '/',
    'memcache.local' => '\\OC\\Memcache\\APCu',
    'apps_paths' =>
            0 =>
                    'path' => '/var/www/html/apps',
                    'url' => '/apps',
                    'writable' => false,
            1 =>
                    'path' => '/var/www/html/custom_apps',
                    'url' => '/custom_apps',
                    'writable' => true,
    'passwordsalt' => 'qq35/QHKLb3SYzjkVp9tIiNtPRVaa1',
    'secret' => '6u5OBS/o4LuNLmIW80nboSIw/g3VI/jrwUaUkYxRFZjhIeMl',
    'trusted_domains' =>
            0 => 'localhost',
            1 => 'http://localhost:8000/plugin'
    'datadirectory' => '/var/www/html/data',
    'dbtype' => 'sqlite3',
    'version' => '',
    'dbname' => 'nextcloud.db',
    'installed' => true,
    'instanceid' => 'ocvxi5l66jxm',
    'allow_local_remote_servers' => true,
    'theme' => '',
    'loglevel' => 2,
    'debug' => true,
    'maintenance' => false,

Thank you for your help :pray:

Just to be sure: Are you trying to access localhost:8000 of your docker host or the docker container?

I suspect you try to access the localhost of the host. Then, you will have use something like If the service you want to access runs under docker, you might connect them directly and access via docker.

Did you try running the request using CLI version of curl? Something like

docker run --rm -it <imageName> /bin/bash
# apt-get update
# apt-get install -y curl
# curl ... http://localhost:8000/plugin

If this is working, the problem is in PHP. If this is not working most probably it’s a generic network problem with docker.