I have created a silly workaround to run and build the docker image inside the docker compose, I used maven so you can replace accordingly with gradle, the concept is not complete but actually might show a way how to use just docker compose up to also build your image in behind via anything (docker in docker :-))
context: ../MyService
dockerfile_inline: |
FROM ubi9:latest
ENV DOCKER_HOST=tcp://127.0.0.1:2375
RUN yum install -y yum-utils
RUN yum-config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
RUN yum install docker-ce-cli -y
COPY . .
RUN --mount=type=cache,target=/root/.m2/repository mvn compile jib:dockerBuild