docker-in-docker: Add an `onCreateCommand` to wait for Docker to be ready
In my devcontainer, which runs as an unprivileged user, Docker was not running properly after the script started up. Editing the script to output more debug info (to make docker info not be quiet) showed it was outputting:
ERROR: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/info": dial unix /var/run/docker.sock: connect: permission denied
Further adding a groups call showed that the user was not in the docker group when we tried to call docker info. This made it always fail when run from the install script. The retry loop ran the maximum number of times, and we were left with several defunct (zombie) docker and containerd processes.
Moving the checking to an onCreateCommand fixes this, as this runs fully as the user. Furthermore, this makes the user's commands, and the container's startup, block on Docker being available. This is beneficial, as it means that there won't be a time when you can use the dev container but Docker isn't there.
We do still keep the retrying logic, and we signal between the onCreateCommand and the install script by creating a flag file.
@microsoft-github-policy-service agree company="Grafana Labs"
Hey @samruddhikhandale. Thanks for the feedback. I can take a look at the other issue. I think features being able to have synchronous initialisation is certainly a better way to do this.
I can't promise to have too much time to dedicate to it, though, so it might take a while. (Don't rely on me!)
I also noticed that this PR isn't 100% reliable even for creation yet - it didn't work in Codespaces, for example. Maybe that's because I need to add it to postStartCommand too. But that's why I left it in draft, was planning to take a look. 😁