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

Should Composite Container Name be the composer.yml path? #278

Open
Fewiel opened this issue Sep 22, 2022 · 1 comment
Open

Should Composite Container Name be the composer.yml path? #278

Fewiel opened this issue Sep 22, 2022 · 1 comment
Assignees

Comments

@Fewiel
Copy link

Fewiel commented Sep 22, 2022

I need to set up a container and get the name back to start and stop it later.

Code to create the container:

var svc = new Builder()
    .UseContainer()
    .WithName("docker-container-1")
    .UseCompose().ServiceName("docker-container-1")
    .FromFile("/root/DockerFiles/test.yml")
    .RemoveOrphans()
    .Build().Start();

test.yml:

version: "3"

services:
    client:
        image: nginx
        ports:
            - 80:80
        volumes:
            - ./src:/usr/share/nginx/html

The svc.Name returns "/root/DockerFiles/test.yml"
I expected it to return: docker-container-1
docker container ls returns the correct container name (but with _client_1 added)

Please let me know if this is the correct way to set the name.

@mariotoffia mariotoffia self-assigned this Sep 23, 2022
@mariotoffia mariotoffia changed the title Get container name returns composer.yml path Should Composite Container Name be the composer.yml path? Sep 23, 2022
@mariotoffia
Copy link
Owner

Hi @Fewiel - this is by design. It will return a ICompositeService and it's composition is determined by the "/root/DockerFiles/test.yml". Inspect the contained services to get their respective name.

If there are any problems, please let me know.

From README.md

      var file = Path.Combine(Directory.GetCurrentDirectory(),
        (TemplateString) "Resources/ComposeTests/WordPress/docker-compose.yml");

      // @formatter:off
      using (var svc = new Builder()
                        .UseContainer()
                        .UseCompose()
                        .FromFile(file)
                        .RemoveOrphans()
                        .WaitForHttp("wordpress", "http://localhost:8000/wp-admin/install.php") 
                        .Build().Start())
        // @formatter:on
      {
        // We now have a running WordPress with a MySql database        
        var installPage = await "http://localhost:8000/wp-admin/install.php".Wget();

        Assert.IsTrue(installPage.IndexOf("https://wordpress.org/", StringComparison.Ordinal) != -1);
        Assert.AreEqual(1, svc.Hosts.Count); // The host used by compose
        Assert.AreEqual(2, svc.Containers.Count); // We can access each individual container
        Assert.AreEqual(2, svc.Images.Count); // And the images used.
      }

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

2 participants