FluentDocker icon indicating copy to clipboard operation
FluentDocker copied to clipboard

Support for docker-compose -H, --host HOST?

Open mario-vuckovic opened this issue 5 years ago • 4 comments

Hi @mariotoffia and thanks for writing this super capable library :)

Some time ago Docker added ssh protocol support to DOCKER_HOST and -H, --host HOST to docker and docker-compose. That means docker-compose can connect directly to the remote machine without depending on docker-machine (provided valid ssh key). Switching between remote targets (on the fly) should also be possible.

Best reference I could find mentioning ssh support is their blog article

I've looked at the code but wasn't able to find where to specify --host parameter when calling docker-compose.

Kind regards.

mario-vuckovic avatar Jul 02 '20 09:07 mario-vuckovic

Hi @mario-vuckovic and thanks for the blog article link! :) I haven't read it yet (just glared) but on top of my head:

All commands, docker and docker-compoe are using the -H {host} flag it is rendered using RenderBaseArgs CommandExtension. In addition it will add the TLS certs as well. --tlsverify --tlscacert={certificates.CaCertificate} --tlscert={certificates.ClientCertificate} --tlskey={certificates.ClientKey}.

For example, when doing compose-up it renders the DockerUri host along withICertificatePaths certificates provided as arguments in the extension method.

So, if I understand your suggestion, you want in addition to commands or set the DOCKER_HOST environment variable, have the ability to have a "ExplicitHostBuilder" where you set a external host (and possibly certificates for TLS that is then used?

For example:

using (
        var container =
          Fd.UseHost()
            .UseSsh("ssh://user@remotehost")
            .UseCompose()
            .Build()
            .Start())
      {
        // Access the remote container here
      }

or using docker-context:

using (
        var container =
          Fd.UseHost()
           .WithContext("remote-daemon")
            .UseCompose()
            .Build()
            .Start())
      {
        // Access the remote container here
      }

The above samples are from the RemoteHostBuilder but have an additional method for Context instead of name (of which referes to a docker-machine name). In addition if a protocol schema is specified it uses the -H switch on the command itself instead of using docker-machine references.

OK?

Cheers, Mario :)

mariotoffia avatar Aug 03 '20 17:08 mariotoffia

In addition @Mario-Hofstaetter is using both setting DOCKER_HOST env (Issue #113) or manually using DockerHostService (Issue #105) to achieve the same thing.

Cheers, Mario :)

mariotoffia avatar Aug 03 '20 17:08 mariotoffia

Hi again @mariotoffia!

Yes, this would be exactly what I'm after:

using (
        var container =
          Fd.UseHost()
            .UseSsh("ssh://user@remotehost")
            .UseCompose()
            .Build()
            .Start())
      {
        // Access the remote container here
      }

My use case consists of service which can connect to multiple remote docker hosts via ssh at the same time (which makes it impossible for me to use DOCKER_HOST env). Host only uses docker-compose cli tool and ssh key has already been added via ssh-add /path/id/id_rsa.

Currently I'm calling docker-compose directly like this: ShellHelper.Bash($"docker-compose -H \"ssh://{username}@{serverIp} \" up -d", dockerComposeFilePath);

Thanks :)

mario-vuckovic avatar Aug 06 '20 12:08 mario-vuckovic

Thanks @mario-vuckovic! I'll add it to my list to do and try to do the coming week (a bit busy this week).

mariotoffia avatar Aug 06 '20 12:08 mariotoffia