Strange curl behavior. Problem with password plugin
giDai7ja opened this issue · 2 comments
Hi!
Running roundcubemail in docker.
I have mailserver running next to it in docker too. I'm trying to make a driver for the password plugin. All I need to do is execute a command: setup email update $username $password
in the container.
I have already checked everything on the host, everything works. Even in two variants: through a Bash script and through a PHP script. Inside the container I have connected /var/run/docker.sock. Both variants work if I execute them inside the container. But when the same commands are executed by the plugin, I get an error:
Failed to connect to v1.41 port 80 after 0 ms: Couldn't connect to server
That is curl
instead of connecting to the socket tries to resolve the name
So curl works differently for the www-data
user and for the root
user
I would be grateful for any ideas on how to solve this problem
Thanks
PS
Maybe there is an easier option to change the password if mailserver
is used?
Code:
...
$data = [
'AttachStdout' => true,
'Tty' => false,
'Cmd' => ['setup','email','update',$username,$password]
];
$jsonData = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_ABSTRACT_UNIX_SOCKET, '/var/run/docker.sock');
curl_setopt($ch, CURLOPT_URL, 'http:/v1.41/containers/mailserver/exec');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($jsonData)
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
...
In continuation of the theme
I run roundcube+nginx+php-fpm on the host and got the plugin working. The code is attached. I tried to move this script to roundcube_docker - the error persisted
I'm not a PHP expert, but I think it's missing something inside the docker
Any ideas?
I'll answer it myself
I still lacked permissions for /var/run/docker.sock
I ran the command setfacl --modify user:www-data:rw /var/run/docker.sock
and everything worked.