zonkyio / embedded-database-spring-test

A library for creating isolated embedded databases for Spring-powered integration tests.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for docker environment when building from Dockerfile

willitrace opened this issue · comments

I have a valid configuration on my SpringBootTests that is successfully running on embedded PostgreSQL database.
Also, running the tests through the GitHub Actions works fine, no issues.

I am using the Docker provider.

However, when I would like to build an image, I am getting the following error:

Caused by: java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration

This is my Dockerfile content:

# Build stage
FROM maven:3.8.6-eclipse-temurin-17-alpine as build
COPY src /home/app/src
COPY pom.xml /home/app
RUN mvn -f /home/app/pom.xml clean package

# Package stage
FROM eclipse-temurin:17-jre-alpine
COPY --from=build /home/app/target/*.jar /opt/app/app.jar
WORKDIR /opt/app
ENTRYPOINT ["/opt/app/entry.sh"]

I am not sure, but is there something special that should be configured to make the docker build work as expected? I was looking into Troubleshooting section without any luck to fix it. There is mentioned that the Docker provider should work inside the Docker container, however, I am not using docker run but docker build and I cannot add volume with the socket.

Support during the build would be very good!

Hi @willitrace,

I think this is not a question related to this project, but rather to the Docker project. So I will try to answer it briefly, but for more information ask there.

The simplest approach is to split the build of the image into two steps. In the first, just run the tests and in the second, build the image without running tests. This is my preferred solution.

The second approach is to use the dind image. In that case, the dind container exposes a url with the docker api, which you can then reference when building the image (the docker build command supports this option). There are of course some basic prerequisites, such as a shared network between those containers and setting the Testcontainers' DOCKER_HOST variable to refer to the Docker API exposed on the dind container. But there may be many more things to deal with, so this approach is much more tricky.