Colima creates a VM and sets up Docker inside it. This is a good command-line replacement for Docker Desktop.
Colima will keep persistent files in a different volume than the VM's root disk, so you can delete and recreate the root disk and your files are still there. This makes recovering from AI 'incidents' easy.
You can have multiple Docker contexts, one for "safe" work (in one VM), and one for "dangerous" AI work (different VM). The only real downside is a VM volume filling up with container images.
Your containers can access the local host's ports using hostname host.docker.internal.
$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common lsb-release
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
$ sudo chmod a+r /etc/apt/keyrings/docker.gpg
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
$ sudo usermod -aG docker $USER
# NOTE:
# - Reboot, or log out and log back in, to get Docker daemon access$ sudo apt install qemu-system-gui virt-top vde2 qemu-user-static qemu-system-x86 $ sudo add-apt-repository -y ppa:jdxcode/mise
$ sudo apt update -y
$ sudo apt install -y mise
$ echo 'eval "$(mise activate bash)"' >> ~/.bashrc
$ eval "$(mise activate bash)"
$ printf "%s\n" "lima latest" "colima latest" >> .tool-versions
$ mise install$ bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"$ brew install colima docker docker-buildx$ colima start \
--cpu 4 \
--memory 4 \
--disk 100 \
--dns 1.1.1.1 \
--dns 8.8.8.8 \
--mount ~/git \
--mount ~/ai-agent-1:rw \
ai-agent-1$ docker context ls
NAME DESCRIPTION DOCKER ENDPOINT ERROR
colima * colima unix:///Users/peterw/.colima/default/docker.sock
colima-ai-agent-1 colima [profile=ai-agent-1] unix:///Users/peterw/.colima/ai-agent-1/docker.sock
default Current DOCKER_HOST based configuration unix:///var/run/docker.sock$ docker context use colima-ai-agent-1
colima-ai-agent-1
Current context is now "colima-ai-agent-1"Create one network for all docker-in-docker containers to use:
$ docker network create -d bridge dind-lab
On MacOS, with Colima, you must always use port forwarding for the docker-in-docker step.
Start DinD, pass through all ports from 8000 to 9000, and mount some directories.
$ docker run \
-d \
--privileged \
--restart=always \
--network dind-lab \
--name dind \
-e DOCKER_TLS_CERTDIR= \
-v dind-lab-data:/var/lib/docker \
-p 8000-9000:8000-9000 \
-v $HOME/git:$HOME/git:ro \
-v $HOME/ai-agent-1:$HOME/ai-agent-1:rw \
docker:27-dind$ docker run \
--rm \
-it \
--network dind-lab \
-p 8000-9000:8000-9000 \
-e DOCKER_HOST=tcp://dind:2375 \
-v $HOME/git:$HOME/git:ro \
-v $HOME/ai-agent-1:$HOME/ai-agent-1:rw \
ubuntu:24.04 bash$ docker run \
--rm \
-it \
--network dind-lab \
-e DOCKER_HOST=tcp://dind:2375 \
-v $HOME/git:$HOME/git:ro \
-v $HOME/ai-agent-1:$HOME/ai-agent-1:rw \
ubuntu:24.04 bashPass through all networking to the host. This is dangerous: it allows the agent to perform network operations as if from your host machine, can conflict with your host's networking, and expose information from the container through your host's tcp/ip stack.
This does not work on MacOS with Colima, but may work with Docker Desktop.
Run Docker-in-Docker with host networking. This is insecure. Use TLS certs and authentication for a bit more security.
Explicitly passes the path to the Docker daemon for more safety, since with host networking, we're playing a dangerous game. May have to change port numbers to not conflict with Docker on your host.
$ docker run \
-d \
--privileged \
--network host \
--name dind \
-e DOCKER_TLS_CERTDIR= \
-v dind-lab-data:/var/lib/docker \
-v $HOME/git:$HOME/git:ro \
-v $HOME/ai-agent-1:$HOME/ai-agent-1:rw \
docker:27-dind dockerd -H unix:///var/run/docker.sock -H tcp://127.0.0.1:2375docker run \
--rm \
-it \
--network dind-lab \
-e DOCKER_HOST=tcp://127.0.0.1:2375 \
-v $HOME/git:$HOME/git:ro \
-v $HOME/ai-agent-1:$HOME/ai-agent-1:rw \
ubuntu:24.04 bash