How to create Docker image with installed metapackage?

I woukd like to install kali-linux-headless
I know that inside dockerfile I can fo apt install xxx -yy

But with the metapackage there are some questions with answer other than yes or no.
For example to choose the user name or something.

How Can I install this package and make it persistent?
I though about volumes but I don’t know which directories inside container I need to connect to volume.

What is your issue exactly? Everything will be persistent that was a result of an instruction in the Dockerfile.

In debian based distros apt upgrade -yy should install everything without asking questions.

But kali-linux-headless during the installation asks about user name for some things.
So during the installation I have different answers than YES or NO.

So how should I configure Dockerfile to install something like this?

I would not even use apt upgrade in a container. Pull the updated base image and build your image from that. If there is a security issue, upgrade a specific package using apt-get install.

Asking for username “for some things” is not enough information to give you a solution. I guess there is a package that requires the username, but I don’t remember if I have ever seen that kind of question using apt upgrade.

I also believe using apt <command> is still not recommended in a script/Dockerfile but I haven’t checked it. I always use apt-get install.

In case of container images you can

  • Pull the up-to-date base image to “upgrade” your packages
  • Build your applications from sourcode so the package manager will not ask you anything and you have the benefit of installing a specific version. We still usse the package manager usually to install dependency libraries.
  • “Tell” the package manager that you are in a non-interactive environment so it should not ask anything from you. In debian based systems you can use the DEBIAN_FRONTEND=noninteractive environment variable.
FROM baseimage

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get install -y --no-install-recommends ...

# ...

If the questions would be to regenerate some configuration files to be compatible with the new version, you need to know exactly what version you are upgrading to and replace the old configuration files by copying the new files into the image after upgrading.