-
-
Save marvell/7c812736565928e602c4 to your computer and use it in GitHub Desktop.
| apt-get clean autoclean | |
| apt-get autoremove --yes | |
| rm -rf /var/lib/{apt,dpkg,cache,log}/ |
Hi guys, simple question: what's the meaning of && rm -rf /var/lib/apt/lists/* given by the docker doc, and should I do it in my Dockerfile?
Anyone who is coming to this gist to remove apt-cache in their docker images; I recommend you to install dive tool and check which directories consume more space in your image. For me; /var/lib folder itself was 53MB, where I could have saved a bunch of MBs on other directories.
A tool for exploring each layer in a docker image
https://github.com/wagoodman/dive
A tool for exploring each layer in a docker image https://github.com/wagoodman/dive
@leiless Thanks for introducing that. really nice.
Hi guys, simple question: what's the meaning of
&& rm -rf /var/lib/apt/lists/*given by the docker doc, and should I do it in my Dockerfile?
@ZYinMD ubuntu:22.04 image had it empty and it increased even if I did apt-get clean. removing it would not harm anything.
- If you have an SSH server on your container, remove your SSH server ASAP. It is not needed to enter inside. That is a FAQ.
There are a number of containers that require allow ssh ingress to the container for legitimate reasons - gitea, gitlab, ssh tunnel deployments, etc
I think the better way to word what you're trying to say is:
If you need to access the shell within the container or execute arbitrary commands inside the container and can remote in to the host, it is advised that you run
docker exec -it <container-name> <shell command>(example:docker exec -it traefik sh) from the host rather than install an SSH server in the container.
Executing rm -rf /var/lib/{apt,dpkg,cache,log}/ will corrupt the apt environment and cause the following error:
Error: Could not open lock file /var/lib/dpkg/lock-frontend - open (2: No such file or directory)
Error: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
Executing
rm -rf /var/lib/{apt,dpkg,cache,log}/will corrupt the apt environment and cause the following error:Error: Could not open lock file /var/lib/dpkg/lock-frontend - open (2: No such file or directory) Error: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
Well yes, these commands should be the last RUN ditective given in the Dockerfile in order to reduce the size of it.
If you need to use apt from within the container later for any reason you can try rm -rf /var/lib/{apt,dpkg,cache,log}/* instead. This will keep the folders but remove their contents.
If you remove the
aptlists and make apt unusable, you might as well remove apt entirelyRUN apt remove apt --autoremove -y --allow-remove-essentialto save 10Mb