How do I specify the model_config_file variable to tensorflow-serving in docker-compose?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
In Docker Compose, you do not usually set model_config_file as a magical environment variable that TensorFlow Serving reads automatically. The standard approach is to mount the config file into the container and pass --model_config_file=... in the container command.
What model_config_file Is For
model_config_file is used when TensorFlow Serving should load models from an explicit configuration file rather than from one single MODEL_NAME and MODEL_BASE_PATH pair. This is the normal pattern for serving multiple models or more structured model setup.
The config is usually written as a textproto file, not as a Compose-specific construct.
Example Model Config File
Create a file such as models.config:
The important part is that the paths inside this file are container paths, not host paths.
Docker Compose Example
Then mount both the model directory and the config file, and pass the flag explicitly:
This is the core pattern. Compose supplies the file. TensorFlow Serving reads it because the command-line flag points to it.
Why the Path Must Match the Container
One common mistake is writing the host path in the config file or in the command:
- host path example:
./models - container path example:
/models
TensorFlow Serving only sees the container filesystem. So if the file is mounted at /models/models.config, that is the path you must pass to --model_config_file.
Single Model Versus Config File
If you are serving only one model, TensorFlow Serving examples often use environment variables or flags like MODEL_NAME and MODEL_BASE_PATH. That is fine for the single-model case.
Use model_config_file when:
- you want multiple models
- you want explicit config-driven loading
- you want config polling for updates
Otherwise the simpler single-model flags may be enough.
Polling and Live Updates
The flag --model_config_file_poll_wait_seconds tells TensorFlow Serving how often to check for config changes. That can be useful when models are added or versioned without recreating the container, but only if the mounted files and model paths are updated in a way the container can see.
Polling is convenient, but it does not replace good deployment discipline. You still need predictable model directory structure and rollout strategy.
Using Compose Variables Deliberately
Docker Compose can still help parameterize the path, but the variable ultimately belongs in the command you pass to TensorFlow Serving. In other words, Compose can substitute values, but TensorFlow Serving still expects the final --model_config_file=... flag.
Verify the File Inside the Container
If TensorFlow Serving says it cannot read the config, shell into the container or inspect the mounted paths and confirm the file exists exactly where the command says it should. Most failures here are path mismatches, not model-serving logic bugs.
Common Pitfalls
- Mounting the config file but forgetting to pass
--model_config_file. - Using host paths in the config instead of container paths.
- Expecting Compose environment variables alone to replace the config file in multi-model setups.
- Mixing single-model environment configuration with multi-model config-file expectations.
- Forgetting to mount the model directories referenced by the config file.
Summary
- In Docker Compose, mount the config file and pass
--model_config_file=...explicitly. - The config file usually becomes necessary when serving multiple models.
- Paths inside the config must match the container filesystem, not the host filesystem.
- '
--model_config_file_poll_wait_secondscan enable periodic config reload checks.' - Treat Compose as the file-mount layer and TensorFlow Serving flags as the runtime configuration layer.
Related reading
- How do I split Tensorflow datasets?
- How do I start tensorflow docker jupyter notebook
- How do I swap tensor's axes in TensorFlow?
- how do I use a very large 2M word embedding in tensorflow?
- How do I store a fitted PCA so that I may transpose unseen testing dataset? I do not wish to keep the large training dataset on my CPU
- How do I tell if a type is a simple type? i.e. holds a single value
- How do I tell if my container is running inside a Kubernetes cluster?
- How do I update the args for a Kubernetes deployment
System design interview problems on this topic
- Design an E-commerce Recommendation System: solution and walkthrough
- Design an LLM Inference Service: solution and walkthrough
- Design a GPU Cluster Scheduler for ML Training: solution and walkthrough
- Design ChatGPT: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.