Skip to content

Codespaces: "Cannot connect to the Docker daemon" occurs randomly (postCreateCommand) #977

@mandrasch

Description

@mandrasch

Hi,

I'm trying to get DDEV - an open source Docker-based PHP development toolkit - working reliably in Codespaces. We already had a discussion here, there were some fixes for docker-in-docker in unversal image in the past (🙏 ) and @eiriksm (and others) provided a wait for docker script for the postCreateCommand, which I thought worked.

#!/bin/bash
set -ex

wait_for_docker() {
  while true; do
    docker ps > /dev/null 2>&1 && break
    sleep 1
  done
  echo "Docker is ready."
}

wait_for_docker

# proceed with commands requiring docker

But for some Codespaces launches I still run into

"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?".

Other launches work fine as expected, current ratio is 5 working, 1 error - seems random.

My devcontainer.json:

{
   "image": "mcr.microsoft.com/devcontainers/universal:2",
   "features": {
       "ghcr.io/ddev/ddev/install-ddev:latest": {}
   },
   // ...
   "postCreateCommand": "chmod +x .devcontainer/postCreateCommand.sh && .devcontainer/postCreateCommand.sh"
}

Example error output:

2024-05-18 08:23:04.024Z: chmod +x .devcontainer/postCreateCommand.sh && .devcontainer/postCreateCommand.sh
2024-05-18 08:23:04.171Z: + wait_for_docker
+ ********
+ docker ps
2024-05-18 08:23:04.666Z: + break
2024-05-18 08:23:04.670Z: + echo 'Docker is ready.'
Docker is ready.
+ ddev debug download-images
2024-05-18 08:23:04.829Z: Downloading ********/docker/compose/releases/download/v2.27.0/docker-compose-linux-x86_64 ... 2024-05-18 08:23:04.839Z: 
2024-05-18 08:23:05.647Z: 
docker-compose 0 B / 60.09 MiB [---------------------------------------]   0.00%2024-05-18 08:23:05.848Z: 
docker-compose 25.86 MiB / 60.09 MiB [==============>------------------]  43.04%2024-05-18 08:23:06.048Z: 
docker-compose 41.45 MiB / 60.09 MiB [======================>----------]  68.99%2024-05-18 08:23:06.235Z: 
docker-compose 60.09 MiB / 60.09 MiB [==============================] 100.00% 0s
Download complete. 
2024-05-18 08:23:20.065Z: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
2024-05-18 08:23:20.078Z: Failed to PullBaseContainerImages(): exit status 1 
2024-05-18 08:23:20.085Z: {"outcome":"error","message":"Command failed: /bin/sh -c chmod +x .devcontainer/postCreateCommand.sh && .devcontainer/postCreateCommand.sh","description":"The postCreateCommand in the devcontainer.json failed.","containerId":"26560cae79c4541c929a677101cf0dea4a9632ceb233c8571c85425a124d2a54"}
2024-05-18 08:23:20.126Z: postCreateCommand failed with exit code 1. Skipping any further user-provided commands.

Full Log: https://gist.github.com/mandrasch/f0ddc7c275c8df68275c88bae5ec9424

My setup: https://github.com/mandrasch/ddev-codespaces-launch-blank
Usage: Browser-based
postCreateCommand: https://github.com/mandrasch/ddev-codespaces-launch-blank/blob/main/.devcontainer/postCreateCommand.sh

Is there a way to debug this? Thanks very much in advance for assistance! 🤗

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions