My Spring Boot application uses ElasticSearch, therefore I have to start an instance of ElasticSearch for integration testing. To start the Docker container of ElasticSearch I use docker-maven-plugin
. The integration test should work on GitLab and on developer machines.
My code works on GitLab's Runner (Docker container) with a Unix socket (see Use Docker socket binding), but not on developer machines.
The internal IP address of the Docker container (172.17.0.2
) is not known with Docker Desktop for Windows (Docker host), see Networking features in Docker Desktop for Windows.
Source
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.33.0</version>
<configuration>
<registry>docker.elastic.co</registry>
<imagePullPolicy>always</imagePullPolicy>
<images>
<image>
<alias>elasticsearch</alias>
<name>elasticsearch/elasticsearch:7.6.2</name>
<run>
<env>
<discovery.type>single-node</discovery.type>
</env>
<wait>
<http>
<url>http://${docker.container.elasticsearch.ip}:9200</url>
<method>GET</method>
<status>200</status>
</http>
<time>60000</time>
</wait>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker:start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>docker:stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Additional informations
- The internal IP is saved in the Maven property
docker.container.elasticsearch.ip
by thedocker-maven-plugin
, see 5.2. docker:start. - The network is by default
bridge
, see 5.2.5. Network. - I can't change GitLab's runner to use Docker in Docker, see Use Docker-in-Docker workflow with Docker executor.
- I can't change GitLab's runner to use shell execution mode, see Use shell executor
Logs
[INFO] DOCKER> Pulling from elasticsearch/elasticsearch
[INFO] DOCKER> Digest: sha256:59342c577e2b7082b819654d119f42514ddf47f0699c8b54dc1f0150250ce7aa
[INFO] DOCKER> Status: Image is up to date for docker.elastic.co/elasticsearch/elasticsearch:7.6.2
[INFO] DOCKER> Pulled elasticsearch/elasticsearch:7.6.2 in 2 seconds
[INFO] DOCKER> [elasticsearch/elasticsearch:7.6.2] "elasticsearch": Start container 121efac6ba65
[INFO] DOCKER> [elasticsearch/elasticsearch:7.6.2] "elasticsearch": Waiting on url http://172.17.0.2:9200 with method GET for status 200.
[ERROR] DOCKER> [elasticsearch/elasticsearch:7.6.2] "elasticsearch": Timeout after 60700 ms while waiting on url http://172.17.0.2:9200
[ERROR] DOCKER> Error occurred during container startup, shutting down...
[INFO] DOCKER> [elasticsearch/elasticsearch:7.6.2] "elasticsearch": Stop and removed container 121efac6ba65 after 0 ms
[ERROR] DOCKER> I/O Error [[elasticsearch/elasticsearch:7.6.2] "elasticsearch": Timeout after 60700 ms while waiting on url http://172.17.0.2:9200]
Research
- Using port mappings and Docker host's IP address from property
docker.host.address
, doesn't work for Unix sockets, see 5.2.9. Wait. - Using
host
network doesn't work for Docker Desktop for Windows, see Use host networking.
Question
Is it possible to use only one docker-maven-plugin
configuration for GitLab and for developer machines?