Skip to content
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

Delete build requirements in Dockerfiles #1199

Closed
davidspek opened this issue Dec 15, 2020 · 4 comments
Closed

Delete build requirements in Dockerfiles #1199

davidspek opened this issue Dec 15, 2020 · 4 comments

Comments

@davidspek
Copy link
Contributor

As requested here as a comment to an open PR of mine, I am opening an issue regarding deleting build requirements from the docker images after they are not needed anymore. The line in question is:

apt-get purge --autoremove -y curl \

Which is installed to add an apt key in the same RUN command and deleted after its use.

@mathbunnyru
Copy link
Member

The purpose of this change is to make the layers and the overall image size smaller.

@romainx
Copy link
Collaborator

romainx commented Jan 5, 2021

Hello @mathbunnyru & @davidspek,

Thanks for this suggestion. However I'm wondering where to apply it.

From the man page

purge is identical to remove except that packages are removed and purged (any configuration files are deleted too).

So from my understanding, it can be used in conjonction with apt-get remove, but we are not removing any packages in the Dockerfiles.

autoremove is used to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed.

So autoremove can be used to clean unused dependencies. But I tried on the last image in the lineage all-spark-notebook and it seems to find nothing to remove.

apt-get autoremove
# Reading package lists... Done
# Building dependency tree       
# Reading state information... Done
# 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Did I miss something? Do you have some use cases in mind?

Many thanks.

@mathbunnyru
Copy link
Member

You're right.
The idea is to remove packages, which were needed to build the image, but not necessary in the resulting image.

https://github.com/jupyter/docker-stacks/blob/master/base-notebook/Dockerfile#L48

For example, we install curl, but I don't think it's really needed in the end.

But I think multi-stage build is a better solution for a given problem.

I think further investigation needs to use https://github.com/wagoodman/dive to really tell, what are the pain points - the places / packages, which take a lot of space, but not needed in the resulting image.

@romainx
Copy link
Collaborator

romainx commented Jan 7, 2021

Hello @mathbunnyru,

Ok got it. However I'm not sure in our case it's worth doing it for wget specially if we consider that it is used in some downstream images and that it can be useful in other circumstances. I would not be 100% for removing it. So I'm closing this issue since we have no defined action to do.

Best.

@romainx romainx closed this as completed Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants