HiveBrain v1.2.0
Get Started
← Back to all entries
patterndockerMinor

Make use of CIs as Maven Repository in order to use it for building Docker images without including dependencies

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
withoutorderdockermakebuildingcisincludingrepositoryformaven

Problem

I am trying to make images from our company Maven based applications. These apps are using some libraries which are included in a Maven repository, but fills a lot of disk space. They also have some dependencies which should be downloaded. I have seen this question which is talking about downloading dependencies (and unfortunately has no approved answer), but for me it is more important to use my local repository without adding it to the image (which increases image size from 300M to 4G) and caching downloading dependencies is in the second place.

If I wanted to ADD my local repository to the image, I would have make this Dockerfile:

FROM java:8.0_31
MAINTAINER Zeinab Abbasimazar (zeinab.abbasi@peykasa.ir)
ADD .m2/ $HOME
WORKDIR .
RUN apt-get update;apt-get install -y maven;cd Development/;mvn clean install -P test
CMD ["./Component.sh &"]


Which makes this image:

sudo docker images
REPOSITORY                                   TAG                 IMAGE ID            CREATED             SIZE
maven                                        3.3.9               44ab79a0bd9e        2 hours ago         4.678 GB


This size for an image is not affordable for me; could anyone please help me on this? Is there any workaround using gitlab or Jenkins to play Maven Repository role?

Solution

Docker images are after all VM templates, i.e. they have to be more or less self-contained: you get the image, you run the environment with all the dependencies.

To approach the challenge operationally, Docker supports reuse of environments through the FROM statement i.e. you could maintain a base image and on top a much smaller image with the app itself.

But, from the strategic point of view, I would say your architects might want consider splitting the whole thing into smaller microservices - that would allow for 5 smaller images. Of course I cannot judge whether it's really possible.

Context

StackExchange DevOps Q#1725, answer score: 2

Revisions (0)

No revisions yet.