I am using docker build kit to build by docker image.
I want bind the host volume to cache the libraries, I am using mount type bind. Here is my docker file. (ref from here and here)
# syntax = docker/dockerfile:experimental
FROM maven:3.6.2-jdk-8-slim AS build
WORKDIR /app
COPY ./pom.xml .
RUN --mount=type=bind,source=/home/ubuntu/.m2,target=/root/.m2,rw mvn clean dependency:go-offline -B
COPY ./src ./src
RUN --mount=type=bind,source=/home/ubuntu/.m2,target=/root/.m2,rw mvn package
FROM tomcat:9.0.30-jdk8-openjdk
COPY --from=build /app/target/service.war /usr/local/tomcat/webapps/
The syntax RUN --mount=type=bind,source=/home/ubuntu/.m2,target=/root/.m2,rw mvn clean dependency:go-offline -B
is throwing following error.
failed to solve with frontend dockerfile.v0:
failed to solve with frontend gateway.v0: rpc error: code = Unknown desc =
failed to build LLB: failed to compute cache key: "/home/ubuntu/.m2" not found: not found
I checked, the path /home/ubuntu/.m2
exists. Is there any issue in syntax?
I was earlier using --mount=type=cache
, it was working perfectly. The reason I want to switch to this is, if the downloaded maven libraries are stored in the host file system it self then even if we do docker system prune --all
, we don't need to download the cached libraries again.