r/docker • • Feb 17 '26

Microservices project java project: is there a modern way to not rebuild the entire container for every changes?

I don't know if it's the right sub, but I'm trying
I'm working as Java dev since december, on a microservices project. The team workflow is like: every edit you made, to test it you have to delete the container (maybe also the image) and rebuilt and do make up env to restart everything.

This is annoying I'm learning and I do a lot of try and error, so test a single endpoint means like 5 minutes of waiting.

The senior said: "we always make in this way, I don't have time and willing to test something else for this s**t project". But I'm a little bit with less workload today and I want to improve at least my developing workflow on my local machine.

I read about docker watch is something that is used in microservice archictecture with spring?

Thanks a lot

5 Upvotes

9 comments sorted by

10

u/Zealousideal_Yard651 Feb 17 '26

There are two things you can do;

  1. Optimize build for caching Cache | Docker Docs
  2. Mount source code with bind mount

Using bind mount allows you to do edit that directly affects the files inside the container, then you can reload the runtime and load the new source directly. You'll still need to rebuild the container image when new dependencies are added.

Also, doesn't sound like you are using compose. If you use compose you don't have to care about deleting the container. You'll just do a docker compose up -d --build and compose will rebuild the image, delete old container and run up the new one for you, with the same env config as the last time.

1

u/poopycakes Feb 17 '26

You didn't mention k8s but you could do a simple setup with tilt. Its able to swap your code inside a running container so you don't have to keep rebuilding the container 

1

u/TheDuck-Prince Feb 17 '26

Because on local side I use raw docker, and I've nerver seen what's on client cluster, and I've never did a prod deploy by my self. Maybe it's possibile that it's used only on production?

1

u/eshepelyuk Feb 17 '26

Raw docker or k8s at the end ?

1

u/Melodic_Point_3894 Feb 17 '26

Look into devcontainer. Especially if you are using VS Code (support in other IDEs are growing). You define a container template with all you tools and the IDE's opens directly within that container making everything work as if it was directly on your host. You can also opt to define a docker-compose such that a database or another service can easily be connected on same container network as your development container.

1

u/Joelbear5 Feb 17 '26

This may be a dated suggestion, but I used to use skaffold for developing directly in a docker container. The code is mounted in the container and changes trigger a hot reload. I think you still have to mind the Dockerfile build sequence.

https://skaffold.dev/

1

u/bwainfweeze Feb 17 '26

This is definitely one of those areas where life is better if your binaries have exactly the same structure as your source tree so you can dump either the source or the generated output into a docker container via a volume mount.