How to run a docker container on a host in a php laravel inside a docker container

We are currently running pphlaravel (api server) as a container using docker.

Among my logics is creating and running docker images of hosts as containers. For example, the docker SDK in phlavel and the docker HTTP in phlavel.

This is not a docker in docker. Question about how to run docker container from php laravel inside docker container to host.

I have tried the following methods at the moment.
#1

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://localhost/containers/create");
    curl_setopt($ch, CURLOPT_UNIX_SOCKET_PATH, "/var/run/docker.sock");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json',
    ]);

    $response = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);

result:

{
    "error": "Couldn't connect to server"
}

#2

$createCommand = sprintf(
"curl --unix-socket /var/run/docker.sock -H 'Content-Type: application/json' -d '%s' -X POST http://localhost/v1.47/containers/create 2>&1",
json_encode([
    'Image' => 'test-image',
    'Cmd' => ['python3', 'main.py', $args1, $args2],
])
);

$createOutput = shell_exec($createCommand);

result:

curl (7) failed to connect

Is there a way to run docker containers on the host from phlaravel inside docker container?