kamal icon indicating copy to clipboard operation
kamal copied to clipboard

Cleanup containers from failed accessory deployments

Open adenta opened this issue 7 months ago • 2 comments

my deploy.yml looks something like this:

# Name of your application. Used to uniquely configure containers.
service: name

# Name of the container image.
image: user/name

# Deploy to these servers.
servers:
  web:
    -  123.4.5.6 # Replace with your actual server IP

# Enable SSL auto certification via Let's Encrypt
proxy:
  ssl: true
  hosts:
    - example.com
    - www.example.com

# Credentials for your image host.
registry:
  password:
    - KAMAL_REGISTRY_PASSWORD

# Inject ENV variables into containers
env:
  clear:
    NODE_ENV: production

# Configure the image builder.
builder:
  arch: amd64

# Aliases for common operations
aliases:
  logs: app logs -f
  remove_container: server exec docker rm -f
  nginx: app exec --interactive --reuse "nginx -s reload"

accessories:
  formbricks:
    proxy:
      ssl: true
      host: forms.sqlhorse.com
      app_port: 3001
      forward_headers: true
      healthcheck:
        path: /
        interval: 5
        timeout: 3
    image: ghcr.io/formbricks/formbricks:latest
    host: 123.4.5.6
    port: "127.0.0.1:3001:3001"
    env:
      secret:
        - WEBAPP_URL
        - NEXTAUTH_URL
        - DATABASE_URL
        - NEXTAUTH_SECRET
        - ENCRYPTION_KEY
        - CRON_SECRET
    directories:
      - formbricks_data:/home/nextjs/apps/web/uploads

I'm trying to package formbricks as a kamal accessory. I botched the boot (I had misconfigured the port mapping), and am now stuck in some sort of death loop:

 sql-horse-marketing git:(main) ✗ kamal accessory details formbricks                         
  INFO [5dff925e] Running docker ps --filter label=service=sql_horse_marketing-formbricks on 123.4.5.6
  INFO [5dff925e] Finished in 1.303 seconds with exit status 0 (successful).
Accessory formbricks Host: 123.4.5.6
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

➜  sql-horse-marketing git:(main) ✗ git push origin pricing-v2        
➜  sql-horse-marketing git:(main) ✗ kamal accessory boot formbricks
  INFO [f2715887] Running /usr/bin/env mkdir -p .kamal on 123.4.5.6
  INFO [f2715887] Finished in 0.818 seconds with exit status 0 (successful).
Acquiring the deploy lock...
  INFO [177a10b5] Running docker login ghcr.io -u [REDACTED] -p [REDACTED] on 123.4.5.6
  INFO [177a10b5] Finished in 0.205 seconds with exit status 0 (successful).
  INFO [acbaa43f] Running docker network create kamal on 123.4.5.6
  INFO [c144171b] Running /usr/bin/env mkdir -p $PWD/sql_horse_marketing-formbricks/formbricks_data on 123.4.5.6
  INFO [c144171b] Finished in 0.160 seconds with exit status 0 (successful).
  INFO [fe88926e] Running /usr/bin/env mkdir -p .kamal/apps/sql_horse_marketing/env/accessories on 123.4.5.6
  INFO [fe88926e] Finished in 0.164 seconds with exit status 0 (successful).
  INFO Uploading .kamal/apps/sql_horse_marketing/env/accessories/formbricks.env 100.0%
  INFO [e4f4a359] Running docker run --name sql_horse_marketing-formbricks --detach --restart unless-stopped --network kamal --log-opt max-size="10m" --publish 127.0.0.1:3001:3001 --env-file .kamal/apps/sql_horse_marketing/env/accessories/formbricks.env --volume $PWD/sql_horse_marketing-formbricks/formbricks_data:/home/nextjs/apps/web/uploads --label service="sql_horse_marketing-formbricks" ghcr.io/formbricks/formbricks:latest on 123.4.5.6
Releasing the deploy lock...
  ERROR (SSHKit::Command::Failed): Exception while executing on host 123.4.5.6: docker exit status: 125
docker stdout: Nothing written
docker stderr: docker: Error response from daemon: Conflict. The container name "/sql_horse_marketing-formbricks" is already in use by container "2d7101a6b6cc70d37c561e673c22e13da1d781a25cbcffee5cfa80a9ab86a358". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.

➜  sql-horse-marketing git:(main) ✗ kamal accessory

The accessory wont boot, AND it's not running. If the container doesn't pass the healthcheck, then the container ends up in a vestigial state of conflict.

adenta avatar May 08 '25 19:05 adenta

Have you tried to manually ssh into the server to remove the the container??

h4nz0x avatar May 21 '25 05:05 h4nz0x

Idk how to do that

---------- Forwarded message --------- From: h4nz0x @.> Date: Wed, May 21, 2025, 1:08 AM Subject: Re: [basecamp/kamal] Cleanup containers from failed accessory deployments (Issue #1545) To: basecamp/kamal @.> Cc: Andrew Denta @.>, Author @.

h4nz0x left a comment (basecamp/kamal#1545) https://github.com/basecamp/kamal/issues/1545#issuecomment-2896602942

Have you tried to manually ssh into the server to remove the the container??

— Reply to this email directly, view it on GitHub https://github.com/basecamp/kamal/issues/1545#issuecomment-2896602942, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACGUU5RJ5JBRHJZLPCNM52T27QC4XAVCNFSM6AAAAAB4XLGYYOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQOJWGYYDEOJUGI . You are receiving this because you authored the thread.Message ID: @.***>

adenta avatar May 21 '25 10:05 adenta