Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't connect to cloud config server, from inside docker compose #2421

Closed
VMM-MMV opened this issue May 23, 2024 · 4 comments
Closed

Can't connect to cloud config server, from inside docker compose #2421

VMM-MMV opened this issue May 23, 2024 · 4 comments

Comments

@VMM-MMV
Copy link

VMM-MMV commented May 23, 2024

Describe the bug
So, I try to connect my spring app to the cloud config server, but it doesn't work when I try to access it after I deploy my app from inside the docker.

networks:
  vd-network:

services:
  config:
    image: hyness/spring-cloud-config-server:3.1.3-jdk11
    deploy:
      labels:
        description: "Spring Cloud Config Server"
      mode: replicated
      restart_policy:
        condition: on-failure
    networks:
      - vd-network
    environment:
      - SPRING_APPLICATION_NAME=config
      - SERVER_PORT=8888
      - SPRING_CLOUD_CONFIG_SERVER_GIT_URI=<URI>
      - SPRING_CLOUD_CONFIG_SERVER_GIT_REFRESH-RATE=3
      - SPRING_CLOUD_CONFIG_SERVER_GIT_USERNAME=<NAME>
      - SPRING_CLOUD_CONFIG_SERVER_GIT_PASSWORD=<PASSWORD>
      - SPRING_CLOUD_CONFIG_SERVER_GIT_DEFAULT-LABEL=main
      - SPRING_CLOUD_CONFIG_SERVER_GIT_SKIPSSLVALIDATION=true
      - ENCRYPT_KEY=<KEY>
    ports:
      - "8888:8888"
  app:
    image: my-image
    ports:
      - "9000:9000"

bootstrap-docker.yaml

  application:
    name: ${name:config}
  cloud:
    config:
      failFast: true
      name: ${name:config}
      profile: ${profile:local}
      debug: true
      uri: ${config.host:http://config:8888}
      label: main
  config:
    import: optional:configserver:${config.host:http://config:8888}

This doesnt work, and If I change it to localhost, it works only when deploying the app directly, but not when running through docker.

What is the reason for the inability to connect. when running through docker?

@ryanjbaxter
Copy link
Contributor

Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.

@VMM-MMV
Copy link
Author

VMM-MMV commented May 29, 2024

The problem was that they were not on the same network. Then after this, I had another problem of the app starting before the cloud config server and requesting the data from it, from an endpoint, but as it was not fully started, it failed. I fixed it by adding:

deploy:
  restart_policy:
    condition: on-failure

Now it fails repeatedly until the server starts and then it is able to connect. I have tried using healthcheck and conditionals, but the cloud server config image does not allow execution from terminal, I tried with wait-for-it.sh, with which I had some other problems. So, in the end I solved it with this. If you have a better solution, please let me know.
So now my app looks something like:

my-app:
  image: my-app-image
  deploy:
    mode: replicated
    restart_policy:
      condition: on-failure
  depends_on:
      - config
  networks:
    - vd-network
  ports:
    - "9000:9000"

@ryanjbaxter
Copy link
Contributor

Thanks for the update!

@VMM-MMV
Copy link
Author

VMM-MMV commented May 29, 2024

No, problem. The less people have to do this, the better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants