testcontainers / testcontainers/testcontainers-java
IllegalState Previous attempts to find a Docker environme when trying to build a simple docker image
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
Hi,
I'm new in using Testcontainers. I tried to use testcontainers 1.16.2 in order to test database integration segments of my app.
The test are working fine when I try the following command:
mvn clean install
but when I'm creating a docker image using the following dockerFile, I'll get IllegalState Previous attempts to find a Docker environme. error.
`
FROM maven:3.8-jdk-11-slim as builder
MAINTAINER Hossein Shemshadi
ENV DOCKER_HOST=tcp://host.docker.internal:2375
COPY src /app/src/
COPY pom.xml /app/
RUN mvn -f /app/pom.xml clean package
FROM openjdk:11.0.6-jre-slim-buster
COPY --from=builder /app/target/agent-matcher-0.0.1-SNAPSHOT.jar /app/agent-matcher-0.0.1-SNAPSHOT.jar
EXPOSE 8090
ENTRYPOINT ["java", "-jar", "/app/agent-matcher-0.0.1-SNAPSHOT.jar"]
`
the error stacktrace is provided below:
[INFO ] 2021-11-09 15:54:04.798/UTC [cluster-ClusterId{value='618a999cca27a43b9470170a', description='null'}-localhost:27017] cluster - Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[mongodb-driver-core-4.2.3.jar:?]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:143) ~[mongodb-driver-core-4.2.3.jar:?]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:188) [mongodb-driver-core-4.2.3.jar:?]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144) [mongodb-driver-core-4.2.3.jar:?]
at java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:?]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) ~[?:?]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242) ~[?:?]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224) ~[?:?]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:?]
at java.net.Socket.connect(Socket.java:609) ~[?:?]
at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:107) ~[mongodb-driver-core-4.2.3.jar:?]
at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) ~[mongodb-driver-core-4.2.3.jar:?]
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongodb-driver-core-4.2.3.jar:?]
... 4 more
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Dockerfile, especially the Maven builder stage and its DOCKER_HOST setting, then inspect pom.xml and the integration tests under src. Reproduce both mvn clean install and the Docker image build, and determine why the Docker build cannot find or connect to the required Docker environment; done means the image build completes with the tests passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java
- Domain
- devops, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100