1

I'm trying to use Testcontainers inside the Multistage Build Dockerfile, and it's currently failing with :

ERROR   --- [           main] o.t.d.DockerClientProviderStrategy       : Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
ERROR   --- [           main] o.t.d.DockerClientProviderStrategy       :     UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (Could not find unix domain socket). Root cause NoSuchFileException (/var/run/docker.sock)
ERROR   --- [           main] o.t.d.DockerClientProviderStrategy       : As no valid configuration was found, execution cannot continue

Is there a way to mount /var/run/docker.sock in a Multistage build ? Or is there an alternative than having to mount the docker.sock ?

jay1648
  • 76
  • 1
  • 6
  • 1
    Docker in docker has serious security problems if this is something you need in a production pipeline . – Thorbjørn Ravn Andersen Aug 18 '22 at 05:20
  • It's only for Testcontainers, which we're using for Integration Testing only. – jay1648 Aug 18 '22 at 09:20
  • 1
    Why do you need Testcontainers as part of building an image? Can you just compile the application without running its integration tests at that point? – David Maze Aug 18 '22 at 10:50
  • 1
    @DavidMaze We're building an image that'll be deployed on prod. And so we want to make sure all tests pass before we build. I understand we can separate it in 2 phases where we first run all CI tests with a separate docker run, and then build the image separately. But only if Docker's multistage build can give us a way to mount docker.sock, we wouldn't need to run it 2 times. – jay1648 Aug 19 '22 at 08:25

1 Answers1

2

To my knowledge, accessing Docker (and specifically the Docker socket of the host at /var/run/docker.sock) is not trivially possible at the current point in time. However, you can configure the Docker build to access the daemon over the network, as outlined in this answer.

Kevin Wittek
  • 1,369
  • 9
  • 26