<p>I have a Spring Boot 2.x project using Mongo.  I am running this via Docker (using compose locally) and Kubernetes.  I am trying to connect my service to a Mongo server.  This is confusing to me, but for development I am using a local instance of Mongo, but deployed in GCP I have named mongo services.</p>

<p>here is my application.properties file:</p>

<pre><code>#mongodb
spring.data.mongodb.uri= mongodb://mongo-serviceone:27017/serviceone

#logging
logging.level.org.springframework.data=trace
logging.level.=trace
</code></pre>

<p>And my Docker-compose:</p>

<pre><code>version: '3'

# Define the services/containers to be run
services:
  service: #name of your service
    build: ./ # specify the directory of the Dockerfile
    ports:
      - "3009:3009" #specify ports forwarding
    links:
      - mongo-serviceone # link this service to the database service
    volumes:
      - .:/usr/src/app
    depends_on:
      - mongo-serviceone

  mongo-serviceone: # name of the service
    image: mongo
    volumes:
        - ./data:/data/db
    ports:
        - "27017:27017"
</code></pre>

<p>When I try docker-compose up . I get the following error:</p>

<blockquote>
  <p>mongo-serviceone_1          | 2018-08-22T13:50:33.454+0000 I NETWORK
  [initandlisten] waiting for connections on port 27017 service_1
  | 2018-08-22 13:50:33.526  INFO 1 --- [localhost:27017]
  org.mongodb.driver.cluster               : Exception in monitor thread
  while connecting to server localhost:27017 service_1
  |  service_1                   | com.mongodb.MongoSocketOpenException:
  Exception opening socket service_1                   |   at
  com.mongodb.connection.SocketStream.open(SocketStream.java:62)
  ~[mongodb-driver-core-3.6.3.jar!/:na]</p>
</blockquote>

<p>running <code>docker ps</code> shows me:</p>

<pre><code>692ebb72cf30        serviceone_service        "java -Djava.securit…"   About an hour ago   Up 9 minutes        0.0.0.0:3009-&gt;3009/tcp, 8080/tcp   serviceone_service_1
6cd55ae7bb77        mongo                      "docker-entrypoint.s…"   About an hour ago   Up 9 minutes        0.0.0.0:27017-&gt;27017/tcp           serviceone_mongo-serviceone_1
</code></pre>

<p>While I am trying to connect to a local mongo, I thought that by using the name "mongo-serviceone"</p>

<p>Hard to tell what the exact issue is, but maybe this is just an issue because of the space " " after "spring.data.mongodb.uri=" and before "mongodb://mongo-serviceone:27017/serviceone"?</p>

<p>If not, maybe exec into the "service" container and try to ping the mongodb with: <code>ping mongo-serviceone:27017</code></p>

<p>Let me know the output of this, so I can help you analyze and fix this issue.</p>

<p>Alternatively, you could switch from using docker compose to a Kubernetes native dev tool, as you are planning to run your application on Kubernetes anyways. Here is a list of possible tools:</p>

<p>Allow hot reloading:</p>

<ul>
<li><strong>DevSpace:</strong> <a href="https://github.com/covexo/devspace" rel="nofollow noreferrer">https://github.com/covexo/devspace</a></li>
<li><strong>ksync:</strong> <a href="https://github.com/vapor-ware/ksync" rel="nofollow noreferrer">https://github.com/vapor-ware/ksync</a></li>
</ul>

<p>Pure CI/CD tools for dev:</p>

<ul>
<li><strong>Skaffold:</strong> <a href="https://github.com/GoogleContainerTools/skaffold" rel="nofollow noreferrer">https://github.com/GoogleContainerTools/skaffold</a></li>
<li><strong>Draft:</strong> <a href="https://github.com/Azure/draft" rel="nofollow noreferrer">https://github.com/Azure/draft</a></li>
</ul>

<p>For most of them, you will only need minikube or a dev namespace inside your existing cluster on GCP.</p>
