kamal icon indicating copy to clipboard operation
kamal copied to clipboard

Accessories are not named distinctly per destination

Open sbleon opened this issue 10 months ago • 2 comments

I'm using Kamal to deploy a Rails app with a postgres database and I'm trying to set up a staging environment on the same server as production. My web containers get complex names, but include "APP-web-staging", where "APP" is the service name from deploy.yml and "staging" is the destination name I've given to Kamal. This is nice for co-location multiple deployments of the same app on a machine.

However, I'm running into problems with postgres, because the database accessory container is just called "APP-postgres", with no destination name included. When I try to setup my staging environment, I get an error like:

docker: Error response from daemon: Conflict. The container name "/APP-postgres" is already in use by container "a67...81b". You have to remove (or rename) that container to be able to reuse that name.

A workaround for this is to change my service name for the staging destination to "APP_staging", but then I'll end up with web container called "APP_staging-staging", which is a little silly. What is the recommended practice for using Kamal-managed accessories in a multiple-deployment-per-machine scenario?

sbleon avatar Feb 14 '25 22:02 sbleon

Yes that is a problem, but probably not fixable without breaking existing deployments.

Does something like this work as a workaround?

accessories:
  postgres:
    service: postgres-<%= ENV["KAMAL_DESTINATION"] %>

djmb avatar Apr 21 '25 11:04 djmb

Thanks for the idea, Donal. I can't easily test that workaround at the moment. Running with the main service key set to [app_name]_[env_name] is working fine for me at the moment, and having a standard prefix for all of the containers is helpful at times.

sbleon avatar Apr 21 '25 13:04 sbleon