Mount a folder running a docker-in-docker container in a custom GitHub action

Viewed 563

I run a docker-in-docker container in my GitHub action and need to mount a folder from the host (repository).

action.yml

...
runs:
  using: 'docker'
  image: 'Dockerfile'
...

Dockerfile

FROM docker:stable
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

entrypoint.sh

...
docker run -d ... -v /github/workspace/.github/config:/opt/dest/config ...
...

The files in the folder do exist under the GITHUB_WORKSPACE from a debug print in the entrypoint.sh. But they appear not to be mounted properly to the inner container.

1 Answers

When using the official docker dind setup, there are two components to it: one container with the Docker CLI (docker:latest) and another container with the Docker Daemon (docker:dind). The Docker-in-Docker containers are created inside the latter container (docker:dind), so that's the one to on which you should setup the host mounts. I suspect you may be setting up the mounts into the Docker CLI container instead.

Another piece of advice: the default Docker-in-Docker setup relies on unprivileged containers or a socket connection to the host's Docker; both provide weak isolation and can mess up your host setup. To get proper isolation, look into Sysbox, a new runc that will enable you to run Docker-in-Docker (and more) much more cleanly.

Related