Background Agent Docker in Docker

What is the best way to get docker in docker supported for background agents? I have pytests fixtures which leverage testcontainers to spin up services like clickhouse. I would like the background agent to be able to run these tests, but I cannot seem to get docker in docker working since I don’t see how to pass the privileged flag.

What is the recommended path for a devcontainer that supports docker test containers?

Thanks!

1 Like

Not using docker to provision the background agent, AI can setup docker environment in the background agent.

There should be a way to do this with dockerfile too.

Been trying this too, was able to install Docker via the convenience script, but trying to run the daemon still fails:

The docs (Cursor – Background Agents) mention this though, so not sure what else needs to be done:

The start command can often be skipped. One common case where you want to use it is if your dev environment relies on docker, in which case you would want to put sudo service docker start in the start command.

I tried replicating this locally and the only way to avoid the “ulimit: error setting limit” error was to use --privileged and --ulimit nofile=65535:65535 like this:

docker run --privileged --ulimit nofile=65535:65535 -it test bash

I don’t think Cursor’s configuration file allows customizing these options though, so still not sure how to get this to work with background agents.

Did you end up figuring this one out? Figured out how to install docker & docker compose in the first place, but when running service docker start I’m getting the ulimit error you have above.

I have the same problem here. My tests depends on using testcontainers to spin-up two ephemeral databases and currently the background agent is unable to run tests. Installing the docker client is simple, but there should be a docker daemon running. Curious about an official solution.

there is a start option in environments json, so you can run docker start.

could you share an example?

Sure,

{
  "snapshot": "POPULATED_FROM_SETTINGS",
  "install": "npm install",
  "start": "sudo service docker start",
  "terminals": [
    {
      "name": "Run Next.js",
      "command": "npm run dev"
    },
    {
      "name": "Watch Files",
      "command": "npm run watch"
    }
  ]
}

When I do this, I get

/etc/init.d/docker: No such file or directory

docker: unrecognized service

hi @Dan_Claroni this is because you are trying to use a Docker based MCP which requires the installation of docker (another software to run the MCP you want).