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

Ductus.FluentDocker.Common.FluentDockerException : Could not dispose composite service from file(s) #291

Open
enrico23 opened this issue May 23, 2023 · 3 comments

Comments

@enrico23
Copy link

enrico23 commented May 23, 2023

I have some integration tests running on Docker using FluentDocker, version 2.10.59

I am using the NUnit lifecycle to create and destroy instances of a Test Environment.

You can see the implementation of the class 'TestEnvironment':

public sealed class SystemTestEnvironment
{
    private SystemTestEnvironment()
    {
        DockerHost = DockerHelpers.GetDockerHost();
        DockerComposeService = Build(DockerHost);
        try
        {
            DockerComposeService.Start();
        }
        catch(Exception ex)
        {
            Debug.WriteLine($"[Fluent Docker Error]: {ex} ");
            DockerComposeService.Dispose();
            throw;
        }
        OnContainerInitialized();
    }

	// ...  code removed  for simplicity

	public static void Initialize()
    {
        Instance = new SystemTestEnvironment();
    }

 		// ...  code removed  for simplicity
           
    
     private ICompositeService Build(IHostService dockerHost)
    {
        return new DockerComposeCompositeService(dockerHost, new DockerComposeConfig
        {
            ComposeFilePath = new List<string> { SqlServerComposeFile },
            ForceRecreate = true,
            RemoveOrphans = true,
            StopOnDispose = true,
            KeepVolumes = false
        });
    }
}

This is the method GetDockerHost

public static IHostService GetDockerHost()
    {
        var hosts = new Hosts().Discover();
        var defaultHost = hosts.FirstOrDefault(x => x.IsNative) ?? hosts.FirstOrDefault(x => x.Name == "default");
        var host = defaultHost ?? (hosts.Count > 0 ? hosts.First() : GetDockerHost());
        if (host.State is not ServiceRunningState.Running)
        {
            host.Start();
        }

        return host;
    }

I am getting the error when I am attempting

 DockerComposeService.Dispose();

The code was working previously on Azure DevOps and still works locally.

I use GitHub Actions and workflow for CI

The Github agent has the following Docker Tooling installed:
Docker version 20.10.24+azure-1
docker-compose version 1.29.2

@mariotoffia
Copy link
Owner

Hi @enrico23 and thanks for the bug report. I do not have access to an azure environment. Have you tried to enable logging and see what commands being emitted and tried them manually. If not, please do and add the commands and which of them were erroneous (if any)?

Cheers,
Mario :)

@enrico23
Copy link
Author

enrico23 commented May 30, 2023

Hi @mariotoffia.
Thanks for looking into it.

I found the issue!

I added the "project name" for the Docker Compose file to determine how it was displayed by Docker Desktop.

version: "3.8"
name: "sqltest1" ########### this line caused the issue ######
services:
    sql-server-db:
        hostname: sqltest1
        container_name: sqltest1-container
        image: mssqltest1
        build:
           context: mssql
           dockerfile: Dockerfile
        ports:
           - "1433:1433"
        environment:
          ACCEPT_EULA: Y
          SA_PASSWORD: ****
          MSSQL_PORT:  1433
          MSSQL_DB: ******
          MSSQL_USER: ******
          MSSQL_PASSWORD: ******
        volumes:
        - ./database/msqqldata:/var/opt/mssql/data
        networks:
        - servicetest1-network
networks:
  servicetest1-network:
    driver: bridge

@theodinspire
Copy link

We're running into a similar item in our Ubuntu build environment. The environment has Docker Compose versions v1 1.29.2 and v2 2.23.3. It looks like docker-compose which is what FluentDocker uses points to v1, but our compose file is set up for v2.

We're currently adding a build step that aliases docker-compose to docker compose

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

No branches or pull requests

3 participants