Create a docker image with service configuration included?

I am playing around with containers and isolation of services, and I don’t really like the systemd containers due to them sharing the whole /nix

So, is it possible to somehow include the configutation in a docker image built with nix?

for example, an empy-basic docker image to run postfix would be something like:

{ pkgs ? import <nixpkgs> { config.packageOverrides = pkgs: { postfix = pkgs.postfix.override { withPgSQL = true; }; }; }
}:

pkgs.dockerTools.buildImage {
  name = "postfix";
  tag = "0.0.1";
  contents = [
    pkgs.postfix
    pkgs.pfixtools
  ];
  runAsRoot = ''
    #!${pkgs.stdenv.shell}
    ${pkgs.dockerTools.shadowSetup}
   # ...add user nobody and mail...
  '';
  config = {
    Cmd = [ "${pkgs.postfix}/bin/postfix" "start" ];
  };
}

But then I would have to mount volumes for the configuration.
I don’t mind mounting the configuration volumes instead of including the conf in the image, but how do I at least generate a conf that is not activated in my main system, so that I can maybe even have multiple instances of the same service with different confs?

IIUC, we want to populate your Docker image with Postfix configuration files which needs to be located in /etc. There are several ways to achieve this.

We can create files and directories with the extraCommands attribute, as used by a |Nginx example image](nixpkgs/examples.nix at 2be8dd990833dc07e338bc27489a211347bf94b9 · NixOS/nixpkgs · GitHub).

We could also use the contents attribute such as:

contents = [
  (pkgs.writeTextFile {
     name = "master.cf";
     destination = "/etc/postfix";
     text = "bla";
   })];

I was hoping more on the lines of reusing services.postfix that I can use in the system configuration.nix, but from your answer I gather that it is not possible.

It will be a bit more verbose, but I guess it’s ok for now, thank you