This error occurs when a Docker Compose service references a config in the `configs` section that hasn't been defined at the top-level `configs` key or doesn't exist as an external Docker config. You need to either define the config in your compose file or create it externally with Docker Swarm.
Docker Compose configs allow you to inject configuration files into containers without baking them into the image. When you reference a config in a service's `configs` section, Docker expects that config to be defined either: 1. In the top-level `configs` section of your docker-compose.yml file 2. As an external config created via `docker config create` (requires Swarm mode) The error 'config "myconfig" is not defined' means the service is trying to use a config named 'myconfig', but Docker can't find its definition anywhere. This is a validation error that occurs before any containers start. Note: The `configs` feature was originally designed for Docker Swarm and has limited support in standalone Docker Compose. In older versions of docker-compose (v1), configs were completely ignored outside of Swarm mode.
The most common fix is to define the config at the top level of your docker-compose.yml. The service references a config name, and that name must be defined in the configs section:
Before (broken):
services:
app:
image: myapp
configs:
- myconfig # References undefined configAfter (fixed):
services:
app:
image: myapp
configs:
- myconfig
configs:
myconfig:
file: ./config/app.conf # Path to local config fileThe file attribute tells Docker Compose where to find the config content on your host machine.
Check that the config name in your service matches the top-level definition exactly, including case:
services:
web:
configs:
- source: nginx_config # Must match exactly
target: /etc/nginx/nginx.conf
configs:
nginx_config: # This name must match the source above
file: ./nginx.confCommon mistakes:
- nginx-config vs nginx_config (hyphens vs underscores)
- NginxConfig vs nginxconfig (case differences)
- Extra whitespace in YAML
If you're using external: true, you must be in Swarm mode and create the config first:
# Initialize swarm mode (if not already done)
docker swarm init
# Create the config from a file
docker config create myconfig ./path/to/config.file
# Verify it was created
docker config lsThen in your compose file:
configs:
myconfig:
external: trueNow docker stack deploy will find the external config.
If you're running docker compose up (not docker stack deploy), avoid external configs and use file-based configs instead:
configs:
app_config:
file: ./configs/application.yml
services:
app:
image: myapp
configs:
- source: app_config
target: /app/config.yml
mode: 0440This approach works without Swarm mode in Docker Compose v2+.
Older docker-compose (Python-based v1) would silently ignore the configs section outside Swarm mode. Docker Compose v2 (Go-based, docker compose without hyphen) has better support:
# Check your version
docker compose version
# If you see v1.x, upgrade to v2
# On Ubuntu/Debian:
sudo apt-get update
sudo apt-get install docker-compose-plugin
# On macOS with Docker Desktop, update Docker Desktop
# Configs support was added around v2.0After upgrading, use docker compose (with space) instead of docker-compose (with hyphen).
If configs aren't working in your environment, bind mounts achieve similar results:
services:
app:
image: myapp
volumes:
- ./config/app.conf:/etc/app/app.conf:roThe :ro flag makes it read-only, similar to how configs work. This approach:
- Works in all Docker versions
- Doesn't require Swarm mode
- Changes to the file on the host are immediately visible in the container
Configs vs Secrets: Docker also has a secrets feature that works similarly but is designed for sensitive data. Secrets are mounted at /run/secrets/ by default and have stricter permissions. Use configs for non-sensitive configuration files.
Swarm mode configs: In Swarm mode, configs are stored in the Raft log and distributed to nodes that need them. They're immutable once created - to update a config, you must create a new one with a different name and update your service.
Config size limits: Docker configs have a size limit of 500KB. For larger configuration files, use volumes or bind mounts instead.
Compose file version: The configs top-level element requires Compose file format version 3.3 or higher. Ensure your compose file specifies an appropriate version:
version: '3.8'Debugging config issues:
# Validate compose file syntax
docker compose config
# List existing configs (Swarm mode)
docker config ls
# Inspect a config's metadata
docker config inspect myconfigimage operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker
cannot open '/etc/passwd': Permission denied
How to fix 'cannot open: Permission denied' in Docker
Error response from daemon: failed to create the ipvlan port
How to fix 'failed to create the ipvlan port' in Docker
toomanyrequests: Rate exceeded for anonymous users
How to fix 'Rate exceeded for anonymous users' in Docker Hub