Molecule "Cannot connect to the Docker daemon" (docker-in-docker) in CI
When the Molecule step runs inside a container: job, that container has no Docker daemon of its own. The docker driver then cannot reach /var/run/docker.sock to create platform instances.
What this error means
Molecule create fails with "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?" only when the job runs in a container.
Cannot connect to the Docker daemon at unix:///var/run/docker.sock.
Is the docker daemon running?
CRITICAL Ansible return code was 2, command was: ... create ...Common causes
The job container has no Docker daemon
A container: job isolates the step from the host; there is no dockerd inside it and no socket mounted, so the driver cannot create instances.
The host socket was not shared into the container
Without mounting the host /var/run/docker.sock, the containerized job cannot use the runner host's daemon.
How to fix it
Run Molecule directly on the runner, not in a container
The simplest fix on GitHub-hosted runners is to run the Molecule step on the host, where Docker is already available.
jobs:
molecule:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install "molecule-plugins[docker]" ansible-core docker
- run: molecule testMount the host socket if a container job is required
If the job must run in a container, share the host Docker socket so the driver can reach the daemon.
jobs:
molecule:
runs-on: ubuntu-latest
container:
image: python:3.12
volumes:
- /var/run/docker.sock:/var/run/docker.sockHow to prevent it
- Prefer running Molecule on the runner host where Docker exists.
- Mount
/var/run/docker.sockinto container jobs that need Docker. - Confirm
docker infofrom inside the job before running Molecule.