Maven Docker build failed with ‘org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375’ on Windows

You can have this kind of error when building a project with Maven and the Docker plugin (by Spotify) :

[INFO] Building image kelios-solutions/annuaire
[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 03:16 min
[INFO] Finished at: 2017-06-29T16:59:30+11:00
[INFO] Final Memory: 32M/78M
[INFO] ————————————————————————
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project annuaire: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.
rs.ProcessingException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect -> [Help 1]

[ERROR]

On Windows, with Docker for Windows, just check if you have exposed the daemon on port 2375 (in Docker for Windows settings) :

image

And your Maven build should create the Docker image.