I need to install on docker the latest version of curl
when using the following the docker size is ~140MB
FROM debian:10.7
RUN apt-get update &&
apt-get install --no-install-recommends -y curl wget ca-certificates
This use curl 7.64
when using the following
FROM debian:10.7
RUN apt-get update &&
apt-get install --yes --no-install-recommends wget build-essential ca-certificates libcurl4 &&
wget https://curl.se/download/curl-7.73.0.tar.gz &&
tar -xvf curl-7.73.0.tar.gz && cd curl-7.74.0 &&
./configure && make && make install &&
apt-get purge -y --auto-remove build-essential &&
The docker image size is 240MB
, I’ve tried to remove the build essintials which reduce the size from 440
to 240
, is there a way to remove this additional ~100MB
?
3
Answers
You should inclide
rm -rf /var/lib/apt/lists/*
into your RUN instruction to remove apt index files and might includeapt-get clean
to remove any other remaining package file.Apart from that, you could also try using the slim image version, according to Docker Hub debian:10.7-slim is almost half size (~24Mb vs ~48Mb)
Finally, you can execute
du -h | sort -h
on a container from your generated image to find out where is the remaining space usage.In fact, you are close to the solution. The one you missed is to delete the curl source package.
So next should make the image reduce:
Without Curl:
With curl & source package delete:
Additional, if you delete apt cache with
rm -rf /var/lib/apt/lists/*
in Dockerfile, if will be smaller:Another solution maybe use multistage-build, you could use
./configure --prefix=xxx
to set a default install location, thenstage1
just used to buildcurl
, whilestage2
copy the xxx folder fromstage1
to final image.Using multistage-build as suggested by atline :
Final size is 129MB