You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This pull request includes a small improvement for the Dockerfile, which should help improve the security of container and reduce the risk of potential attacks.
In detail:
I added --no-install-recommends to remove unnecessary apt packages, that were not needed for the container's functionality. Not only can this change trim your image size but it also can also reduce the attack surface.
I hope that you find them useful. Please let me know if you have any concerns.
I updated the differences between the builds before and after the improvement as below:
The image size slightly reduces from 85.3MB to 84.9MB, likely because you removed the base packages (with apt-get purge) after using them.
The number of newly installed packages reduces from 386 pkgs to 163 pkgs (avoid 223 unnecessary packages)
Without --no-install-recommends in your Dockerfile, I think the installation of many unnecessary packages consumes more network bandwidth and time.
Moreover, in general, avoiding the installation of unnecessary packages is highly recommended for the security of your Docker containers.
As quoted from CIS Docker Benchmark v1.5.0:
4.3 Ensure that unnecessary packages are not installed in the container Description:
Containers should have as small a footprint as possible, and should not contain unnecessary software packages which could increase their attack surface. Rationale:
Unnecessary software should not be installed into containers, as doing so increases their attack surface. Only packages strictly necessary for the correct operation of the application being deployed should be installed.
I hope you find this additional information helpful.
For your information, below logs are extracted from the build logs before and after the improvement.
after looking at the output of dpkg -l on both images, the patch basically just gets rid of the manpages package, which means that all the extra stuff that was being installed was also being removed.
All in all the size gain is negligible, the security benefit is about zero, but on my laptop, the image build a lot faster (3:15 down from 5:45), I'll take that win.
Merged, thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
This pull request includes a small improvement for the Dockerfile, which should help improve the security of container and reduce the risk of potential attacks.
In detail:
--no-install-recommendsto remove unnecessaryaptpackages, that were not needed for the container's functionality. Not only can this change trim your image size but it also can also reduce the attack surface.I hope that you find them useful. Please let me know if you have any concerns.
Thank you.