0

I'm trying to import a file using "spring.config.import". I saw in the documentation that you can import in 2 ways. 1 using multiple files (configtree) and the other is where the file is a .yaml file.

I've seen issues from others, but they're using configtree and I'd like to use yaml file instead because it can store multiple variables more easily IMO:

When running the app, it always says:

Config data resource 'file [config/backend-secrets.yaml]' via location 'file:./config/secrets.yaml' does not exist

Here is a simple compose file that I have

services:
  backend:
    image: ghcr.io/acemint/something:main
    container_name: backend
    environment:
      SPRING_CONFIG_IMPORT: file:./config/backend-secrets.yaml
    secrets:
      - backend_secrets
    volumes:
      - ./config/secrets/:/config
2
  • 1
    Your environment variable is pointing at ./config, relative to the current directory, but your bind mount is at /config, an absolute path. Commented Apr 29, 2024 at 16:18
  • Thanks, I've found that actually it is not because of the relative path, but it' actually due to the workdir in my Dockerfile Commented Apr 29, 2024 at 16:28

1 Answer 1

0

Solution: Change the path of the yaml to the WORKDIR of your Dockerfile

volumes:
  - ./config/secrets/:/app/config

Explanation: Given a simplified version of my Dockerfile below, I'm running my .jar on /app, which automatically means that while it seems that the app is trying to search from /config, it is searching from /app/config. Hence the volume should be mounted to /WORKDIR/....

# syntax=docker/dockerfile:1
FROM eclipse-temurin:21-jdk-alpine as build

# Set cwd to /app
WORKDIR /app

# Copy the executable JAR file from the build stage
COPY --from=build /app/target/x-admin-0.0.1-SNAPSHOT*.jar /app.jar

# Define the default command to run the Spring Boot application
CMD ["java", "-Dserver.port=${PORT}", "-Dspring.profiles.active=production", "-jar", "/app.jar"]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.