The Linux Page

Useful Docker Commands

Retrieve a Docker Image

You found an image and you have a URL now you want to get a copy, you do a pull like so:

docker pull gcr.io/distroless/static

It will load that image in docker.

List Files in a Docker Image

I often would like to see the files inside a docker image. The fact is that Docker has a tarball of those files that one can export to see said files.

First you can try the save command like so:

docker save <image-uuid> > foo.tar

If that doesn't seem to work, you can try the following few steps to check out your image contents by first creating a container:

docker create --name foo <image-uuid> /app/foo
docker export foo > foo.tar
docker rm foo

The "/app/foo" looks weird since that is not likely to exist in that image but Docker wants that if the image does not include an ENTRYPOINT tag. It wants to have some way to handle the docker run command and that's what will be used (and fail in this case because it won't exist).

Now you have a foo.tar file which is the file system of that docker image.

Full Docker Cleaning

To clean everything, after you removed things you don't need anymore, you can use the prune command like so:

docker system prune

and make sure you say 'y'es to the question if you want to proceed.

See also: My hard drive looks full