Detach mode is not taking my parameters into account

Hi everyone,

I am experiencing a problem/issue with my Spring Boot base application while running it in a Docker container using Docker Compose.

While the application is launched using the following command: docker-compose pull && docker-compose up -d, the container is unable to find the active profiles, the Spring profiles are not taken into account but while not using the -d, it works just fine though I’m stuck with my terminal.

To be more precise about the problem, my Spring Boot application behaves differently in detached mode compared to the “normal way”, specifically regarding the activation of Spring profiles. In detached mode, the application does not seem to recognize the SPRING_PROFILES_ACTIVE environment variable.


  • Spring Boot version: 3.0.6
  • Docker version: Ubuntu 22.04 64bit with Docker
  • Docker-compose version: v2.21.0

Steps to reproduce the bug:

  • Run docker-compose up - The application works fine, and the profiles are active.
  • Run docker-compose up -d - The application starts, but the profiles are not active (fall back to the default profile).

My already made steps and tries (before melting away)

  • Checked environment variables inside the container.
  • Compared logs in both modes.
  • Tried to pass the environment variables (SPRING_PROFILES_ACTIVE) in my docker compose file with and without the commas

Also, if there are dev ops or someone who can answer my questions, but it’s facultative, here there are:

  • Why would the Spring profiles not be recognized when running the Docker Compose in detached mode?
  • Is there a difference in how environment variables or application properties are processed between these two modes? Have any suggestions on how to ensure that the profiles are consistently recognized regardless of the mode in which Docker Compose runs?

Here is my Dockerfile from my backend:

# Amazon Corretto with Java 20.0.2 as the base image
FROM amazoncorretto:20.0.2

# Metadata as a label
LABEL maintainer="anonymized" version="0.0.1-SNAPSHOT" description="Santa Secret project"

# Declare JAR_FILE as a variable
ARG JAR_FILE=target/work-0.0.1-SNAPSHOT.jar

# Copy the JAR file into the container
COPY ${JAR_FILE} app.jar

# Specify the base command to run the jar
ENTRYPOINT ["java","-jar","/app.jar",",secretProd"]

My docker compose file, which is located in the root of the folder:

version: '3.8'

    image: myHubName/secretsanta-backend:latest
      - "8080:8080"
      SPRING_PROFILES_ACTIVE: "dockerLocal,secretProd"
      SPRING_DATASOURCE_URL: jdbc:postgresql://database:5432/${POSTGRES_DB}
      - database

    image: myHubName/secretsanta-frontend:latest
      - "80:80"

    image: postgres:latest
      - postgres_data:/var/lib/postgresql/data


Here is my file:

I would appreciate it if anyone helps.

Detached mode means your client is not attached to the standard streams (output, error, input) of the process running in the container, but that doesn’t really change anything unless somehow your application detects it, but I don’t know how that would be possible.

The only difference I saw is that some applications can stop when I run it in attached mode because resizing the terminal (for example) sends a signal (SIGWINCH) which is used by HTTPD as a stop signal, but it shouldn’t affect environment variables.

You can test it by changing the command of the container and just run “env” to show the variables.

Have you tried to run the container without docker compose only using docker run?

First of all, thank you for your response ! :slight_smile:

Oh right, i see !

Yes, i was actually running the containers without docker compose and using docker run !
The strangest thing is, my spring boot application while launched in detached mode is not seeing the profiles, which is odd
But while using the -d, Docker is not being able to connect anymore.

What does it mean not seeing a profile?

connect to what? Please show error messages if you have.

For further example, here is the docker compose comportment while using the docker compose up, as you can see with my poor editing skills, the active profile is “prod”

Sorry, I had to do a second post due to the two images

And then, while using docker compose up -d (do not mind the --env-file .env command ), it’s not behaving in the same way as it should have :frowning:

You could have just copy and paste the text and share it in a code block: How to format your forum posts

Then we can read it much better than on a screenshot and we can quote parts of it or copy and search for something. Please, avoid using screenshots unless you share something which can’t be shared as a text or you can’t copy it. Thanks.

Why not? That could be the reason easily. Why did you add that parameter?