Run Claude in Docker for AI-Assisted Development
At this point in time I’m using Claude Code as code assistant for my daily work. I have adopted it as a generator for pretty specific tasks, like generating types, writing UI pages with components that I have already implemented, generate tests, generate endpoints for the services I have integrated or domain logic I have prepared before.
Pretty much the outer layer of my software is generated by Claude Code, then I review it, apply it, test it and move on.
Of course theres cases where I rather writing it myself, or when I found my self in the 3rd try to generate a specific piece of code, I just stop and write it myself.
So its helpful, but not perfect.
In any case, I’m kind of a security concerned guy, and I don’t like the idea of any arbitrary command/code running on my machine at any point without my consent.
So I take advantage of Docker containers and its isolation capabilities to run Claude Code in a container, and I only give it access to the folders I want it to have access to. Usually that folder is a single repository.
As I was copying the same Dockerfile
and docker-compose.yml
to every project I wanted to
integrate with Claude Code, I decided to create a base image that I can use as a base for all my
projects.
Let me introduce you to leoborai/claude-code Docker image.
Usage
I usually create a dev
directory where the Dockerfile
and docker-compose.yml
would be, like I
did in my DeckMaster project.
Even though I still use the dev
directory, to split logic from actual project/domain logic, the Dockerfile
is no needed anymore, as I can use the image directly.
services:
claude:
image: 'ghcr.io/leoborai/docker-claude:latest'
volumes:
- ../:/workspaces/dev
command: sleep infinity
With this docker-compose.dev.yml
file, I can run docker compose -f docker-compose.dev.yml up -d
and have a
container running with Claude Code installed, and my project mounted in /workspaces/dev
.
Then I just exect into the container with docker exec -it <container_id> /bin/bash
and start using
Claude Code as regular.
Conclusion
This is a simple way to run Claude Code in a secure way, and have it isolated from my machine. Feel free to checkout the repo here: https://github.com/LeoBorai/docker-claude and provide any suggestions or improvements via either issues or PRs.
Happy Coding!