8

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?

giliermo
  • 141
  • 1
  • 8

1 Answers1

8

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.

Chanseok Oh
  • 3,920
  • 4
  • 23
  • 63
  • 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 ? – giliermo Mar 27 '20 at 06:33
  • 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). – Chanseok Oh Mar 27 '20 at 13:58
  • Where shall the docker-compose.yaml file be placed? – vic Apr 24 '20 at 01:54
  • And how to make sure the command ./mvnw spring-boot:build-image will pick up the yaml file? – vic Apr 24 '20 at 03:23
  • @vic 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. – Chanseok Oh Apr 24 '20 at 14:01
  • @ChanseokOh Thanks for your clarification. I just started using those tools. – vic Apr 25 '20 at 04:34