How to create docker-compose.yml file while using jib?
Asked Answered
L

1

9

I use jib plugin to create image, while docker-compose needs Dockerfile. How can i Link already made image by jib to my docker-compose so it can build my backend in process?

Lucielucien answered 26/3, 2020 at 7:34 Comment(0)
J
9

gradle jibDockerBuild && docker-compose up is a reasonable workaround. You just need to set a correct image name in the image: property (instead of build:) in docker-compose.yml. The jibDockerBuild command will be almost no-op (barring the time needed to push an image to your Docker daemon) when there is no change to your app. When you make a change, Jib will build a new image and docker-compose will use it. Of course, if you don't have to rebuild the image by Jib, docker-compose up alone will suffice, which will just use the current image in your Docker daemon cache.

Another option: pushing to and pulling from a registry (whether local or remote) with gradle jib && docker pull <your image> && docker-compose up may be faster if your image is large and you have decent network bandwidth. (This is because Docker Engine API has limited capability compared to Docker Registry API; Jib has to stream an entire image to a Docker daemon with jibDockerBuild.

Jugulate answered 26/3, 2020 at 16:50 Comment(7)
So i should build image with jib first and tell docker-compose to use it right? It creates tar file as you know , so i should unzip it in a go ?Lucielucien
No, using jibDockerBuild, Jib directly pushes an image to your local Docker engine. It doesn't create a tarball. Let's say you did -Djib.to.image=example.com/foo/image. Then in your docker-comose.yml, you just say image: example.com/foo/image without build: .. Docker Compose will use the image in your local Docker engine. If example.com/foo/image doesn't exist in your Docker daemon, Docker Compose will try to download it from a remote registry (and fail because the server example.com doesn't have the image).Jugulate
Where shall the docker-compose.yaml file be placed?Brantley
And how to make sure the command ./mvnw spring-boot:build-image will pick up the yaml file?Brantley
@Brantley Docker Compose is just a container runtime platform and is completely independent of your project, Spring Boot, or Jib. Similar to that you can maintain Kubernetes yaml files anywhere, you can have docker-compose.yaml anywhere you like. spring-boot:build-image is Spring's way to building an image and doesn't use Jib. spring-boot:build-image produces a very inefficient image, so you shouldn't use it when you configured Jib. Use Jib's jib:build or jib:dockerBuild instead.Jugulate
@ChanseokOh Thanks for your clarification. I just started using those tools.Brantley
docker-compose up will work only for the first time. If you want to refresh the container with the new image you have to add --force-recreate. Also, the docker-compose is not supported anymore and the docker compose should be used instead.Oteliaotero

© 2022 - 2025 — McMap. All rights reserved.