Can't start docker daemon inside container

369 Views Asked by At

I have a docker image based on amazonlinux:2.0.20220912.1 with Amazon Corretto Java SDK 11 installed.

I have also added a docker installation to this image by using this command in the Dockerfile

RUN amazon-linux-extras install docker

I use this image to run a gradle build of a Spring Boot project in a Jenkins pipeline. To make things even more complex, the Jenkins pipeline is using the Jenkins docker function called inside() which mounts the Jenkins workspace in the container and then run the groovy closure inside the container.

def dockerImage = docker.image("my docker image")
dockerImage.inside("--entrypoint='' -e AWS_DEFAULT_REGION=${region}") {
    sh './gradlew test'
}

The Spring Boot project have a junit test that use testcontainers so docker must be available inside the container. But when the test attempts to start a test container I get this error

java.lang.IllegalStateException: Could not find a valid Docker environment.

A lot of googling suggest I need to start a docker daemon inside the container. The problem is, I can't find a way to start it. Some google hits say I should use systemctl start docker, but that fails

Failed to get D-Bus connection: Operation not permitted

Other hits suggest using the command service docker start but there is no command service in the image.

So what is the magic incantation to start a docker daemon inside an amazonlinux:2.0.20220912.1 container?

0

There are 0 best solutions below