mariotoffia / FluentDocker

Use docker, docker-compose local and remote in tests and your .NET core/full framework apps via a FluentAPI
Apache License 2.0
1.31k stars 97 forks source link

Replicate non-fluent code snippet using Fluent API? #264

Open DustinReagan opened 2 years ago

DustinReagan commented 2 years ago

I'm currently unable to replicate the following non-fluent code in the Fluent API:

var id = _docker.Host.Run("mcr.microsoft.com/dotnet/sdk:6.0", new ContainerCreateParams()
         {
              Interactive = true,
              Volumes = new []{$"{appDir}:/app", $"{nugetConfigPath}:/app/nuget.config" },
              WorkingDirectory = "/app",
         }, _docker.Certificates).Data;
         var response = _docker.Host.Execute(id, "ls", _docker.Certificates);
         //var response = _docker.Host.Execute(id, "dotnet restore /p:Configuration=Release --use-lock-file", _docker.Certificates);
         _docker.Host.RemoveContainer(id);

Here's what I've tried:

var userProfileDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
        var appDir = Path.Combine(userProfileDir, "code/legacy/LEAF/modules-telephonebanking/TelephoneBanking.Service");
        var nugetConfigPath =  Path.Combine(userProfileDir, ".nuget/NuGet/NuGet.Config");

        using (var container =new Builder()
                   .UseContainer()
                   .UseImage("mcr.microsoft.com/dotnet/sdk:6.0")
                   .Mount(appDir,"/app", MountType.ReadWrite)
                   .Mount(nugetConfigPath, "/app/nuget.config", MountType.ReadOnly)
                   .UseWorkDir("/app")
                   .Build()
                   .Start())
        {
            var response = container.Execute("ls");

        }

When I try this I get error messages similar to : Error response from daemon: Container e0e92da3262235e7d970ef588910e6bb4fa04c195ea6d9757285c08837aaeed7 is not running.

I can't seem to find how to run the container in interactive mode in the Fluent API.

Finally, how do I simply run an existing Dockerfile using the Fluent API? I've looked through the examples and APIs and can't seem to find how to do this.

mariotoffia commented 2 years ago

Hi @DustinReagan and thanks for the report!

I'll add support for interactive for fluent API on my TODO list.

When it comes to use a docker file, the documentation states the below - doesn't this work?

        using (var services = new Builder()
          .DefineImage("mariotoffia/nodetest").ReuseIfAlreadyExists()
          .FromFile("/tmp/Dockerfile")
          .Build().Start())
        {
         // Container either build to reused if found in registry and started here.
        }

It can be found under Using the Fluent API

Cheers, Mario :)

DustinReagan commented 2 years ago

@mariotoffia Oh, I apologize for missing that in the docs, thanks!