tensorflow-serving
docker-compose
model_config_file
machine-learning
deployment

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.

Practice ML system design

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:

text
1model_config_list: {
2  config: {
3    name: "classifier"
4    base_path: "/models/classifier"
5    model_platform: "tensorflow"
6  }
7  config: {
8    name: "recommender"
9    base_path: "/models/recommender"
10    model_platform: "tensorflow"
11  }
12}

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:

yaml
1services:
2  tfserving:
3    image: tensorflow/serving
4    ports:
5      - "8500:8500"
6      - "8501:8501"
7    volumes:
8      - ./models:/models
9      - ./models.config:/models/models.config:ro
10    command: >
11      --model_config_file=/models/models.config
12      --model_config_file_poll_wait_seconds=60

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_seconds can enable periodic config reload checks.'
  • Treat Compose as the file-mount layer and TensorFlow Serving flags as the runtime configuration layer.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design