Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you uninstall APK and PIP from Docker Image?

I'm working on some "common sense" hardening of one of my docker containers and my line of thinking suggests that I could attempt to uninstall APK and PIP from the Alpine linux image after I finish installing all of my dependencies.

I'm having a hard time finding any information on doing so. My line of thinking is that the container is ephemeral so there would never be a need to install anything to a running container.

Anybody ever done this? Thanks!

like image 260
G. Ball Avatar asked Jan 29 '19 15:01

G. Ball


People also ask

Does uninstalling docker remove images?

2 Answers. All the data is in /var/lib/docker . However, this data will not be removed when uninstalling the packages.

How do I uninstall docker software?

To remove one or more Docker containers, use the docker container rm command, followed by the IDs of the containers you want to remove. If you get an error message similar to the one shown below, it means that the container is running. You'll need to stop the container before removing it.

What is APK docker?

&& apk add bash tells Docker to install bash into the image. apk stands for Alpine Linux package manager. If you're using a Linux base image in a flavor other than Alpine, then you'd install packages with RUN apt-get instead of apk.


2 Answers

You should be able to remove pip by uninstalling the py-pip package:

apk del py-pip

Followed by deleting pip's cache:

# rm -rf /<HOME_DIR>/.cache/pip

Then, for removing apk, delete the apk binary and folders:

# rm -f /sbin/apk
# rm -rf /etc/apk
# rm -rf /lib/apk
# rm -rf /usr/share/apk
# rm -rf /var/lib/apk

I haven't done Docker hardening/jailing myself, but removing the package manager seems like a common practice for reducing the possible attack surface. Here's an interesting post taking a similar approach:

  • Minimising your attack surface by building highly specialised docker images - example for .NET Core 2.1 applications
like image 95
valiano Avatar answered Oct 24 '22 17:10

valiano


For removing apk, this will also work and ensure proper removal: apk --purge del apk-tools

like image 4
Dane Kantner Avatar answered Oct 24 '22 17:10

Dane Kantner