Reputation: 2738
If I run a docker build
that pulls down maven dependencies into an .m2 repository, that doesn't persist in the image.
So if I then try to i) tty into a running container, my ~/.m2/repository
directory will be empty. Or ii) if I build another image on top of the first, those deps will have to be downloaded again.
Contents of my Dockerfile
are here.
FROM maven:3.5.0-jdk-8-alpine
RUN apk update \
&& apk add ca-certificates \
&& update-ca-certificates \
&& apk add openssl \
bash \
git
WORKDIR /app
COPY . /app
RUN mvn compile
I'm sure this is some simple detail of docker that I'm not understanding. Anyone have any insights there?
Upvotes: 2
Views: 2408
Reputation: 2738
@khmarbaise Yes, you're right. I just had to specify a VOLUME /root/.m2/repository
entry in my Dockerfile. I also removed cached containers and volumes, just to be sure. And sire enough, the repository is there, as I expect.
So my Dockerfile now looks something like this. I didn't have a full grokking of docker volumes. But that all makes sense now. Thanks.
FROM maven:3.5.0-jdk-8-alpine
RUN apk update \
&& apk add ca-certificates \
&& update-ca-certificates \
&& apk add openssl \
bash \
git
WORKDIR /app
COPY . /app
VOLUME /root/.m2/repository
RUN mvn compile
Upvotes: 1