admin管理员组

文章数量:1287116

I'm deploying a Spring Boot microservice using Docker Compose, but it's still trying to fetch its configuration from http://localhost:8888 instead of the config-service container.

Spring Boot Configuration (application.yml):

spring:
  application:
    name: ${APP_NAME:iam-service}
  cloud:
    config:
      uri: ${CONFIG_SERVER_URI:http://localhost:8888}
      name: iam-service,security-conf,eureka-properties
      profile: ${PROFILE:dev}
  config:
    import: "configserver:"

# Server Configuration
server:
  servlet:
    context-path: ${CONTEXT_PATH:/api/v1/iam}
  port: ${IAM_SERVER_PORT:8881}

Docker Compose Configuration (docker-compose.yml):

version: "3.8"

services:
  iam-service:
    container_name: iam-service
    image: ${DC_IMAGE_NAME}:${DC_IMAGE_TAG}
    ports:
      - 8881:8881
    environment:
      - CONFIG_SERVER_URI=http://config-service:8888
      - IAM_SERVER_PORT=8881
    networks:
      - ms-network  
    restart: always

networks:
  ms-network:
    external:
      name: ms_network

Issue: Despite setting CONFIG_SERVER_URI=http://config-service:8888 in Docker Compose, the logs show:

Fetching config from server at : http://localhost:8888

It seems that Spring Boot is not picking up the environment variable. I've verified that the container is running on the correct network and that config-service is reachable.

本文标签: Spring Boot Microservice Not Using CONFIGSERVERURI from Docker ComposeStack Overflow