Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list all applications that are contained in a docker container?

Tags:

docker

I have downloaded a docker container that performs several different operations on an input file using several different kinds of software, i.e. alignment, variant calling etc. How do I find out what the contents of the docker container/image is? Sorry if this is trivial I am totally new to docker.

like image 407
Martin S Avatar asked Sep 05 '19 10:09

Martin S


People also ask

What command is use to list all the Docker?

In order to list the Docker containers, we can use the “docker ps” or “docker container ls” command. This command provides a variety of ways to list and filter all containers on a particular Docker engine.

What does a docker container contains?

A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

How do I see what processes are running in a Docker container?

Like it was mentioned, if you are already inside of a container, then just use ps -eaf command to see the running processes.

Where are Docker apps stored?

The docker images, they are stored inside the docker directory: /var/lib/docker/ images are stored there.


3 Answers

There are (at least) three ways to interpret your question:

  • which packages are installed in the container;
  • what files are there: explore container's filesystem;
  • what images and layers does the container consist of?

1. List packages installed in container

The way to get list of installed packages depends on distribution. There are three most popular families:

  • Alpine, lightweight Linux distribution based on musl and BusyBox
  • Debian-based (Debian, Ubuntu)
  • rpm-based (RHEL, CentOS and Fedora)

Alpine-based containers

Use apk info -vv command:

docker exec -i <container_id_1>  apk info -vv | sort

Debian & Ubuntu - based containers

Use dpkg -l command:

docker exec -i <container_id_1>  dpkg -l

RHEL, CentOS and Fedora - based containers

Use rpm -qa or yum list installed command:

docker exec -i <container_id_1>  rpm -qa
docker exec -i <container_id_1>  yum list installed

2. Explore container's filesystem

To see directory structure you can use either bash & tree or cool tools developed specially for exploring docker images

tree

docker exec -i <container_id_1> tree /

Note: not all images contain tree command.

docker export with tar

docker export adoring_kowalevski > contents.tar And then, tou can explore contents.tar with your preferred archiver. I.e. for tar:

tar -tvf contents.tar

3. Special tools (explore images and layers OverlayFS)

wagoodman/dive

wagoodman/dive: A tool for exploring each layer in a docker image

docker run --rm -it \ 
  -v /var/run/docker.sock:/var/run/docker.sock \
  wagoodman/dive:latest \
  <image_name|image_id>

A tool for exploring a docker image, layer contents, and discovering ways to shrink your Docker image size. Image

tomastomecek/sen

TomasTomecek/sen: Terminal User Interface for docker engine

docker run -v /var/run/docker.sock:/run/docker.sock -ti -e TERM tomastomecek/sen

it can interactively manage your containers and images:

justone/dockviz

justone/dockviz: Visualizing Docker data

$ dockviz containers -d -r | dot -Tpng -o containers.png

Containers are visualized with labelled lines for links. Containers that aren't running are greyed out.

$ dockviz containers -d -r | dot -Tpng -o containers.png

like image 132
Yasen Avatar answered Nov 15 '22 11:11

Yasen


You can get information concerning the image by using: docker image inspect <image> and docker image history <image> and then if you want to get information concerning the container, simply enter in the running container using exec command docker container exec -itu 0 <container> /bin/bash(pay attention your container may be using another shell) and afterward just gather the needed information (os, running processes, open files, etc)

More information about exec command: https://docs.docker.com/engine/reference/commandline/exec/.

PS: To list images docker image ls , to list running containers docker container ps

like image 37
dejanualex Avatar answered Nov 15 '22 10:11

dejanualex


Since Docker Desktop 4.7.0 you can use the experimental sbom command to get the "Software Bill of Rights", which is a pretty comprehensive list of all contained libraries and corresponding versions. E.g.

$ docker sbom openjdk:11-jre-slim-buster
Syft v0.43.0
 ✔ Pulled image
 ✔ Loaded image
 ✔ Parsed image
 ✔ Cataloged packages      [91 packages]

NAME                    VERSION                  TYPE
adduser                 3.118                    deb
apt                     1.8.2.3                  deb
base-files              10.3+deb10u12            deb
base-passwd             3.5.46                   deb
bash                    5.0-4                    deb
bsdutils                1:2.33.1-0.1             deb
ca-certificates         20200601~deb10u2         deb
coreutils               8.30-3                   deb
dash                    0.5.10.2-5               deb
debconf                 1.5.71+deb10u1           deb
debian-archive-keyring  2019.1+deb10u1           deb
[...]

As you can see it's based on Syft which is third party tool. That may change in the future though (hence experimental). In fact you can also use Syft directly so you don't need Docker Desktop.

like image 38
David Ongaro Avatar answered Nov 15 '22 09:11

David Ongaro