Docker Community Forums

Share and learn in the Docker community.

Best practice(s) for initial setup needed within a docker-compose container?

I am setting up a service where most containers are pretty straightforward (e.g. nice Docker images that take either ENV variables or straightforward config files provided as volumes…) but one requires some arcane and host-specific setup before the container is really ready to launch.

Specifically, I need Samba working in “Domain Controller” (fake Active Directory) mode within the docker-compose service. I’ve worked out a proof-of-concept for this: a Dockerfile PLUS a series of several additional setup steps/scripts that are host-specific. (Basically the “normal server” process is one installs Samba, and then runs a helper wizard script thing that generates a config file but also installs more random dependencies and seeds some local binary files…)

It’s unclear to me what the best practice is here:

  1. I’m assuming I could manually set up that container outside of my docker-compose.yml file and reference from the rest of the composed ones anyway
  2. I’m scripting the overall process via Ansible, so I suppose that after the docker-compose up–equivalent step I could add some steps to that Ansible recipe that finish the “manual” setup of the troublesome Samba container
  3. Or I could just add on to my Dockerfile [or a second Dockerfile referencing the first] the steps that make it ready to server one particular Active Directory domain from one particular host, and reference that from my docker-compose. This might be the easiest but feels the most “wrong” to me for some reason since it sort of changes the Dockerfile in sort of a pets vs. cattle way
  4. Or I suppose I could track down everything the Samba “setup wizard” does and sort it out myself — e.g. the Python dependencies would go straight in the Dockerfile, the text-based configuration file would go in my docker-compose repo and get --volume-d in, same with the binary database files that it pre-seeds as volumes, etc.
  5. Finally I suppose I could engineer a whole special entrypoint script that detects if setup is needed or not, and if not leverages ENV variables and whatnot. I think this is what many Official images must do for e.g. MariaDB user/database setup or whatnot but this one feels like the most work to get right especially for an image I wasn’t planning on pushing to any registry or desire to maintain/support for the general public [I am *not* a Samba expert and would rather not play one on GitHub…!]

Are “host-specific” Dockerfiles encouraged? I.e. ones that preconfigure for a very particular purpose/configuration?

Or is it better to split out the dynamic files (basically the state that the Samba configuration wizard thing creates) into a folder in the repo with my docker-compose file itself, and mount that as a volume? I’m not excited about recreating the Samba wizard myself, and it feels weird to have binary blobs in a git repo but as I write this up that seems like a reasonable compromise.

But the real question is: am I missing another obvious-in-hindsight option that keeps this all even simpler? What do Docker experts do in this situation: where a vendor has its own script that needs to run once when the container is first created but then [at least as long as the container isn’t re-created?] is good to go as far as the overall service goes?