Coder Social home page Coder Social logo

shrink image about golang HOT 16 CLOSED

docker-library avatar docker-library commented on August 27, 2024
shrink image

from golang.

Comments (16)

proppy avatar proppy commented on August 27, 2024

I think cgo might require gcc, so I'm not sure if it's "safe" to remove in all cases.

from golang.

cpuguy83 avatar cpuguy83 commented on August 27, 2024

Aah, you are right.

If we leave libc6 and gcc in there image shrinks to 406.7MB
Not a huge gain... but also nice to be explicit about the build-deps instead of installing build-essential.

from golang.

yosifkit avatar yosifkit commented on August 27, 2024

That sounds good to me.

I got it to 385MB by adding rm -r /var/lib/apt/lists/* after the apt-get install lines. I can have a PR shortly, if you would like. The only drawback I see is that all the golang versions had a common layer and now will all be different, but your proposed changes are what we have been doing in the other images.

FROM debian:wheezy

ENV GOLANG_VERSION 1.3.1
# Go building deps and SCMs for "go get"
RUN apt-get update && apt-get install -y \
        ca-certificates curl gcc libc6-dev \
        bzr git mercurial \
        --no-install-recommends \
    && rm -rf /var/lib/apt/lists/* \
    && curl -sSL http://golang.org/dl/go$GOLANG_VERSION.src.tar.gz \
        | tar -v -C /usr/src -xz \
    && cd /usr/src/go/src && ./make.bash --no-clean 2>&1 \
    && apt-get purge -y curl \
    && apt-get autoremove -y

ENV PATH /usr/src/go/bin:$PATH

RUN mkdir -p /go/src
ENV GOPATH /go
ENV PATH /go/bin:$PATH
WORKDIR /go

from golang.

proppy avatar proppy commented on August 27, 2024

Maybe instead of combining all the command with &&, we could have a script in the context that does the same w/ set -e.

from golang.

tianon avatar tianon commented on August 27, 2024

What benefit would that provide except less predictable cache behavior and
now two places to look to see how the image was built?

Also, what affect (if any) does this refactor have on our cross builds?

from golang.

proppy avatar proppy commented on August 27, 2024

@tianon how does that make it less predictable?

My understanding is that:
In one case, if the .sh change the layer is invalidated.
In the other, if the line change the layer is invalidated.

from golang.

tianon avatar tianon commented on August 27, 2024

It's less predictable because "mtime" is included in the "if the .sh is
changed" calculation, which is changed on every fresh "git clone" (which is
exactly how these images are built). It's predictable for individual users
on their own systems, but not for the official image build system, is what
I meant.

from golang.

yosifkit avatar yosifkit commented on August 27, 2024

I am testing the cross builds and have one more adjustment (for packages that are not uninstalled).

FROM debian:wheezy

RUN apt-get update && apt-get install -y \
        ca-certificates gcc libc6-dev \
        bzr git mercurial \
        --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

ENV GOLANG_VERSION 1.3.1

# Go building deps and SCMs for "go get"
RUN apt-get update && apt-get install -y --no-install-recommends curl \
    && rm -rf /var/lib/apt/lists/* \
    && curl -sSL http://golang.org/dl/go$GOLANG_VERSION.src.tar.gz \
        | tar -v -C /usr/src -xz \
    && cd /usr/src/go/src && ./make.bash --no-clean 2>&1 \
    && apt-get purge -y curl \
    && apt-get autoremove -y

ENV PATH /usr/src/go/bin:$PATH

RUN mkdir -p /go/src
ENV GOPATH /go
ENV PATH /go/bin:$PATH
WORKDIR /go

from golang.

proppy avatar proppy commented on August 27, 2024

@tianon: got it, and that's not true for the Dockerfile where each line is actually considered even if mtime has changed.

I didn't realize that the "official build system" was leveraging caching, I just assumed it was using --no-cache.

from golang.

proppy avatar proppy commented on August 27, 2024

@yosifkit I'm confused why there is 2x apt-get update. Can't we have one big shell expression and remove /var/lib/apt/lists at the end?

from golang.

yosifkit avatar yosifkit commented on August 27, 2024

They are in separate RUN's because I was trying to optimize the docker cache so that all the go versions can depend on the same layer (since we were not removing any of those packages).

from golang.

proppy avatar proppy commented on August 27, 2024

@yosifkit oh, make sense sorry for the noise, but this does come at the expense of 1 additional apt-get update, right?

Maybe the size of curl is negligible enough that you could leave it in the image and get read of the apt- stuff in the second case?

from golang.

yosifkit avatar yosifkit commented on August 27, 2024

Yes there is one additional apt-get update. Even though the size or curl itself is minimal (~1MB), by cleaning up build dependencies after install we will set precedent for further official images to keep them as tidy as possible.

Semi-unrelated question: is ca-certificates necessary, or can we clean it up with curl?

from golang.

tianon avatar tianon commented on August 27, 2024

Go does use it if your app hits SSL, so I think we need to keep that one.

from golang.

yosifkit avatar yosifkit commented on August 27, 2024

I have a PR for the changes discussed here. I decided to leave the curl since it made a smaller amount of changes.

from golang.

tianon avatar tianon commented on August 27, 2024

Yeah, I think that's fair, especially at only 1MB (and since curl is so
useful).

from golang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.