-
Notifications
You must be signed in to change notification settings - Fork 263
Can I connect via https and with basic auth? #354
Comments
The DockerEngine does not have any basic auth support. The DockerEngine itself doesn't even have a user system so i'm wondering where you even got the credentials from that you tried to use. You can access the DockerEngine API via a local unix socket, http without any auth or using ssl certificates (https). You can find an explanation on how to configure https here: https://docs.docker.com/engine/security/https/ Then use the following config to create the client: $context = stream_context_create([
'ssl' => [
'cafile' => 'path/to/ca.pem',
'local_cert' => 'path/to/cert.pem',
'local_pk' => 'path/to/key.pem',
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]);
$client = DockerClientFactory::create([
'remote_socket' => 'tcp://dock.localhost:2376',
'ssl' => true,
'stream_context' => $context
]);
self::$docker = Docker::create($client); Hope this helps you (: |
@JanHolger this is easy to do through any reverse proxy or balancer. |
Well but this is a library for connecting to the docker engine api, not some unofficial custom proxy you made, that nobody knows how its designed. If you need the library to connect to your custom proxy setup, fork it and implement the auth logic yourself and don't ask this project to do so. Solution: A function that might be working (im not experienced with php-http): function createClient(array $config = [], PluginClientFactory $pluginClientFactory = null): HttpClient
{
$messageFactory = new GuzzleMessageFactory();
$socketClient = new SocketHttpClient($messageFactory, $config);
$host = $config['remote_socket'];
$pluginClientFactory = $pluginClientFactory ?? new PluginClientFactory();
return $pluginClientFactory->createClient($socketClient, [
new ContentLengthPlugin(),
new DecoderPlugin(),
new AddHostPlugin(new Uri($host)),
new AuthenticationPlugin(new BasicAuth($config['username'], $config['password']))
], [
'client_name' => 'docker-client',
]);
} Usage: $client = createClient([
'remote_socket' => 'tcp://dock.localhost',
'ssl' => true,
'username' => 'your-username',
'password' => 'your-password'
]);
self::$docker = Docker::create($client); Please do the research yourself next time. It didn't took me too long to read the docs of php-http... |
php -m | grep openssl
openssl
The text was updated successfully, but these errors were encountered: