Jonathan Bennett

Using Accessories to Extend Your Kamal Projects

We previously explored how to integrate a Docker image into a Kamal project. Did you know you can also use it as an accessory in an existing deployment? This approach extends Kamal’s utility, allowing you to enhance your projects with additional services seamlessly.

Kamal accessories can leverage any Docker image to extend your application’s capabilities. While DockerHub is the default image source, you can specify other registries, such as ghcr.io, by including the full image address.

Here’s an example configuration to integrate Metabase and its database as accessories in an existing project:

accessories:
	metabase:
		image: metabase/metabase:v0.52.1.1
		host: 1.2.3.4
		port: 80 # expose publically
		env:
			clear:
				MB_DB_TYPE: postgres
				MB_DB_HOST: PROJECT-metabase_db
				MB_DB_PORT: 5432
				MB_DB_DBNAME: metabase
				MB_DB_USER: metabase
				MB_DB_PASS: metabase
				MB_JETTY_PORT: 3000
				JAVA_OPTS: -Xmx2g
	
	metabase_db:
		image: postgres:16.1-alpine
		host: 1.2.3.4
		port: 5432:5432 # only expose to the docker network
		directories:
			- data:/var/lib/postgresql/data
		env:
			clear:
				POSTGRES_DB: metabase
				POSTGRES_USER: metabase
				POSTGRES_PASSWORD: metabase
				# this could be moved to secrets, but its only exposed to the local 

Run kamal accessory boot for both metabase and metabase_db, and your new services will be live in no time.