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

Set container name to a deterministic value when launching #949

Closed
analogrelay opened this issue Nov 19, 2023 · 15 comments · Fixed by #1835
Closed

Set container name to a deterministic value when launching #949

analogrelay opened this issue Nov 19, 2023 · 15 comments · Fixed by #1835
Assignees
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Comments

@analogrelay
Copy link

When launching an Aspire app, the created containers are just given the default random docker names:

CONTAINER ID   IMAGE                  COMMAND                  CREATED         STATUS         PORTS                       NAMES
5ce3d9b00a89   plenary/shell:latest   "/shell/entrypoint.sh"   2 minutes ago   Up 2 minutes                               nice_swirles
166f578bc2a6   postgres:latest        "docker-entrypoint.s…"   2 minutes ago   Up 2 minutes   127.0.0.1:55839->5432/tcp   friendly_kirch

I have configured my app with a "shell" container to allow invoking dotnet tools like dotnet-ef in the context of a service, and I need to docker exec into it in order to run those commands. It'd be helpful if the containers had a consistent name like [app]_[resource] or similar, much like how docker-compose sets names. Then I could avoid having to look up the container name and could more easily script interactions with running containers (such as execing in to them).

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Nov 19, 2023
@davidfowl
Copy link
Member

Also worth following this issue #398

@analogrelay
Copy link
Author

Yep, I think the container name change is somewhat orthogonal to my specific case, so I filed this. I can see utility in exec-ing in to the running containers for various reasons. I'll chime in on the other issue with specific thoughts for EF tooling.

@DamianEdwards
Copy link
Member

@davidfowl @karolz-ms @mitchdenny would changing the container naming logic require changes just to the app model or in DCP too?

@mitchdenny
Copy link
Member

Container banking is handled by DCP.

@analogrelay
Copy link
Author

@DamianEdwards I was actually going to send a PR but I quickly found that it was handled by DCP 😢

@DamianEdwards DamianEdwards added area-orchestrator and removed area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication labels Nov 20, 2023
@karolz-ms
Copy link
Member

@mitchdenny short of better devault in DCP, try passing --name desired-container-name via Container.Spec.Args; I believe that should do the trick https://github.com/dotnet/aspire/blob/main/src/Aspire.Hosting/Dcp/Model/Container.cs#L42

@dbreshears
Copy link
Contributor

dbreshears commented Jan 8, 2024

DCP side of this was checked in for Preview 2.

@mitchdenny mitchdenny self-assigned this Jan 10, 2024
@davidfowl
Copy link
Member

cc @JamesNK

@JamesNK JamesNK self-assigned this Jan 25, 2024
@JamesNK
Copy link
Member

JamesNK commented Jan 25, 2024

I looked into this, and it is working today without any changes required in hosting. DCP now automatically sets a container name unless one is explicitly specified from hosting.

image

(Docker requires unique names. The random postfix on each name is a safety measure to prevent duplicates)

I'll update our DCP DTOs to include the new property, but we don't need to use it.

@DamianEdwards
Copy link
Member

Are we adding support for setting the desired container name from an AppHost project?

@davidfowl
Copy link
Member

I guess we need another issue?

@DamianEdwards
Copy link
Member

#1855

@pedershk
Copy link

(Docker requires unique names. The random postfix on each name is a safety measure to prevent duplicates)

I'll update our DCP DTOs to include the new property, but we don't need to use it.

The hostname changes with each restart of debugging for containers managed by the AppHost. This breaks RabbitMQ queue persistence (with fixed volume mounts configured as well) as queues are bound under a hostname directory. RabbitMQ's internal RabbitMQ naming can be changed by setting the NODENAME environment variable on the container which overrides this behavior - but this can be a source of frustration as no indication as to why queues disappear appear in any log.

The following works to override this behavior - but the .WithEnvironment("NODENAME", "rabbit@localhost") statement should perhaps be a default when using the AddRabbitMQContainer method?

 var docGenRabbitMq = builder
     .AddRabbitMQContainer("rabbitmq-docgen", 9002, password: rabbitMqPassword)
     .WithEnvironment("NODENAME", "rabbit@localhost")
     .WithVolumeMount("rabbitmq-docgen-vol", "/var/lib/rabbitmq", VolumeMountType.Named);

@JamesNK
Copy link
Member

JamesNK commented Feb 15, 2024

@pedershk Could you create a new issue? That will ensure it will get looked at.

@pedershk
Copy link

pedershk commented Feb 15, 2024

Could you create a new issue? That will ensure it will get looked at.

Yes, sorry, didn't even notice that this one was closed. I blame lack of coffeee.

#2247

@github-actions github-actions bot locked and limited conversation to collaborators Apr 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants