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

It is unclear that Docker Compose services have not been started as one or more is already running #38398

Closed
lianej opened this issue Nov 20, 2023 · 4 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@lianej
Copy link

lianej commented Nov 20, 2023

Version: spring-boot-docker-compose:3.1.2

I have created a project using spring-boot-docker-compose that lists three services (let's call them A, B, and C) in the compose.yml file. Everything works as expected on the first launch.

However, after the containers are created, if I manually start the container for service A using the Docker API (docker start $service_A_container_id), and then attempt to start the Spring application again without first stopping it, the spring-boot-docker-compose skips the container startup phase. This results in services B and C not being started correctly.

Upon inspecting the code, I found the cause of this issue lies in the condition used to determine whether the Docker API should be called in org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager#start:

if (lifecycleManagement.shouldStart() && runningServices.isEmpty()){
    ...
}

This condition stipulates that no currently running services should be found.

I believe the startup phase should not be skipped in this scenario for the following reasons:

  1. If the service I'm starting is a database, there are instances where I would want to connect to the database to inspect data without needing to start the entire application. This necessitates the ability to start the container independently.
  2. The Docker-Compose API supports the restarting of already started containers. Hence, removing the restriction to skip startup wouldn't lead to any errors.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 20, 2023
@wilkinsona
Copy link
Member

This behavior is intentional. We tried to clarify the documentation in #36483.

If the service I'm starting is a database, there are instances where I would want to connect to the database to inspect data without needing to start the entire application. This necessitates the ability to start the container independently.

You can still do this if you then stop the container before starting the app.

The Docker-Compose API supports the restarting of already started containers. Hence, removing the restriction to skip startup wouldn't lead to any errors.

That may not be what the user wants and restarting may lose a non-persistent change that had been made to the container.

If we want to support something in this area, I think we'd have to offer a configuration option and make restarting already running containers an opt-in feature.

@lianej
Copy link
Author

lianej commented Nov 21, 2023

That may not be what the user wants and restarting may lose a non-persistent change that had been made to the container.

I agree.

Could we provide clearer error messages or warning log for services are partially running?

@wilkinsona
Copy link
Member

Spring Boot does not parse the compose YAML file so we don't know how many services should be running. All we can easily detect at the moment is that one or more services is running. Given this, I think an error or warning would be too much. We could perhaps log an info level message indicating that the services won't be started as one or more is already running. We'll discuss this as a team and decide what, if anything, we want to do.

@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Nov 22, 2023
@mhalbritter
Copy link
Contributor

We could use the compose config command to detect that not all defined services are running (we do that for org.springframework.boot.docker.compose.core.DefaultDockerCompose#hasDefinedServices). However, I don't think we should do that.

We could perhaps log an info level message indicating that the services won't be started as one or more is already running.

That's fine for me.

@wilkinsona wilkinsona changed the title spring-boot-docker-compose is going to skip the startup of services if some of the services are running. It is unclear that Docker Compose services have not been started as one or more is already running Dec 4, 2023
@wilkinsona wilkinsona added type: bug A general bug and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Dec 4, 2023
@wilkinsona wilkinsona added this to the 3.1.x milestone Dec 4, 2023
@mhalbritter mhalbritter self-assigned this Dec 5, 2023
@mhalbritter mhalbritter modified the milestones: 3.1.x, 3.1.7 Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants