skip to Main Content

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


  1. You should inclide rm -rf /var/lib/apt/lists/* into your RUN instruction to remove apt index files and might include apt-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.

    Login or Signup to reply.
  2. 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:

    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.73.0 && 
        ./configure && make && make install && 
        apt-get purge -y --auto-remove build-essential && 
        cd .. && rm -fr curl-7.73.0.tar.gz curl-7.73.0
        
    

    Without Curl:

    $ docker images abc:1
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    abc                 1                   d742bfdf5fa6        25 seconds ago      148MB
    

    With curl & source package delete:

    $ docker images abc:2
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    abc                 2                   afe3d404852a        27 minutes ago      151MB
    

    Additional, if you delete apt cache with rm -rf /var/lib/apt/lists/* in Dockerfile, if will be smaller:

    $ docker images abc:3
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    abc                 3                   5530b0e9b44f        2 minutes ago       134MB
    

    Another solution maybe use multistage-build, you could use ./configure --prefix=xxx to set a default install location, then stage1 just used to build curl, while stage2 copy the xxx folder from stage1 to final image.

    Login or Signup to reply.
  3. Using multistage-build as suggested by atline :

    FROM debian:10.7 AS builder
    
    WORKDIR /app
    RUN mkdir /app/usr2
    
    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.73.0 && 
        ./configure --prefix=/app/usr2 && make install
    
    FROM debian:10.7
    
    RUN apt-get update && 
        apt-get install --no-install-recommends -y wget ca-certificates &&
        rm -rf /var/lib/apt/lists/*
    
    COPY --from=builder /app/usr2/. /usr
    

    Final size is 129MB

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search