Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mario-vuckovic opened this issue Jul 2, 2020 · 4 comments · May be fixed by #162
Open

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

mario-vuckovic opened this issue Jul 2, 2020 · 4 comments · May be fixed by #162
Assignees
Milestone

Comments

@mario-vuckovic
Copy link

mario-vuckovic commented Jul 2, 2020

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.

@mariotoffia
Copy link
Owner

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 mariotoffia self-assigned this Aug 3, 2020
@mariotoffia mariotoffia added enhancement waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further. labels Aug 3, 2020
@mariotoffia mariotoffia added this to To do in FluentDocker via automation Aug 3, 2020
@mariotoffia mariotoffia added this to the 3.0.0 milestone Aug 3, 2020
@mariotoffia
Copy link
Owner

mariotoffia commented Aug 3, 2020

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 :)

@mario-vuckovic
Copy link
Author

mario-vuckovic commented Aug 6, 2020

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 :)

@mariotoffia mariotoffia removed the waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further. label Aug 6, 2020
@mariotoffia
Copy link
Owner

mariotoffia commented Aug 6, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
FluentDocker
  
To do
Development

Successfully merging a pull request may close this issue.

2 participants