-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The image is 425 MB larger than it should be #11396
Comments
add in S163. |
Multi stage builds is a potential solution and we already used it in RPM build. I will first figure out how many directories we need to copy from the first build to the second one and see if it's feasible. |
Absolutely. If, as you alluded to, it doesn't get too messy with how much
stuff you have to COPY.
…On Tue, Dec 3, 2019 at 6:37 AM Feng Zhou ***@***.***> wrote:
Multi stage builds <https://stackoverflow.com/a/47441295> is a potential
solution and we already used it in RPM build
<https://github.com/Azure/azure-cli/blob/dev/scripts/release/rpm/Dockerfile.centos>.
I will first figure out how many directories we need to copy from the first
build to the second one and see if it's feasible.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11396?email_source=notifications&email_token=AAMKRPBA76LX4SBPSOE6QVTQWZHHNA5CNFSM4JRVISWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFZHGGQ#issuecomment-561148698>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAMKRPEGU2LH6MY75QJ2EA3QWZHHNANCNFSM4JRVISWA>
.
|
This PR: #12208 is a quick fix to save 400+ MB space for the image. After ignoring tests files, the source code only wastes about 12 MB space. I think we can live with that now without using experimental mode. I also found another solution with experimental mode, that is to use --squash for docker build. |
@mattlorimor Thanks for bringing up this issue and providing a solution. We definitely learned something valuable from your sharing. We welcome you to provide any feedback in the future. |
Is your feature request related to a problem? Please describe.
The pulled image,
mcr.microsoft.com/azure-cli
, at 1 GB is 425 MB larger than it should be due to this line not behaving as whoever wrote it expected.While running
rm -rf ./azure-cli
does, in fact, hide the directory from the subsequent layers, it does not remove it and its bloat from the built image. Proof of this can bee seen by using a tool such asdive
to inspect the image.Describe the solution you'd like
Find a way to actually remove the no-longer-needed source code from the finished container.
The trickiness of this is compounded by the fact that this is python and pip is involved. It's not like there is a single binary being generated that could simply be built in a separate stage and copied to the final stage.
I found a solution for this locally, but I'm not sure how feasible it would be on your end considering it requires the Docker daemon to be running in experimental mode. The new
Dockerfile
would look something like this:The big changes are:
# syntax = docker/dockerfile:experimental
at the top of the
Dockerfile
and then using the--mount
flag in the run command:Doing this allows
RUN
to use the source code without aCOPY
and prevents it from being forever committed to an intermediate layer.Building this version resulted in a functional image 586 MB in size.
Describe alternatives you've considered
If you could somehow make it so that you could pull down the source with a
RUN
instead of aCOPY
, it could be done andrm -rf
'd in the same layer as the currentinstall_full.sh
command.Additional context
It looks like the exact same thing is happening, at the very least, in
Dockerfile.spot
.The text was updated successfully, but these errors were encountered: