Search code examples
dockercontainersapt

Accessing upgradable packages using 'apt list --upgradable' from Docker container


I'm attempting to access the list of upgradable packages on my host system from within a Docker container using apt list --upgradable to export the count of upgradable packages as a metric.

I've tried mounting /var/lib/apt, /var/cache/apt and /etc/apt into the container, but I'm still unsure if I have all the necessary directories mounted to retrieve this information completely.

Here's an example command I'm using to run the container:

docker run -v /var/lib/apt:/var/lib/apt \
           -v /var/cache/apt:/var/cache/apt \
           -v /etc/apt:/etc/apt \
           -it --rm ubuntu:22.04 apt list --upgradable

Despite mounting these directories, when I execute apt list --upgradable within the container, I'm not getting the expected list of upgradable packages. Is there anything missing or any additional steps needed to retrieve the full list of upgradable packages using apt list --upgradable from within a Docker container?

Any suggestions, insights, or guidance would be greatly appreciated. Thank you!


Solution

  • Figured it out with the help of @Nick ODell.

    The directory /var/lib/dpkg has to be mounted to get the right result from apt list --upgradable. None of the other directories is needed.