# Docker Config Not Found: How to Create and Manage Swarm Configs

Your Swarm service fails to deploy because a referenced config doesn't exist:

bash
Error response from daemon: rpc error: code = 2 desc = config nginx_config not found

Or:

bash
service myapp: failed to update service: config not found: app_settings

Docker Swarm configs store non-sensitive configuration data. Services fail if referenced configs aren't created first. Let me show you how to fix this.

Understanding Docker Swarm Configs

Configs are similar to secrets but: - Not encrypted at rest - Mounted in / by default (configurable) - Can be updated without creating new versions - Suitable for non-sensitive configuration files

Step 1: List Existing Configs

Check what configs exist in your Swarm:

```bash # List all configs docker config ls

# Output: # ID NAME CREATED # abc123 nginx_config 2 hours ago

# Inspect a config docker config inspect nginx_config

# Show config content (base64 encoded) docker config inspect nginx_config --format '{{.Spec.Data}}' | base64 -d ```

Step 2: Create Missing Configs

If the config doesn't exist, create it:

```bash # Create from file docker config create nginx_config ./nginx.conf

# Create from stdin cat <<EOF | docker config create app_config - server { listen 80; root /var/www/html; } EOF

# Create from existing file with specific name docker config create myapp_config_v1 ./config.json

# Verify creation docker config ls | grep nginx_config ```

Unlike secrets, configs can be viewed after creation:

bash
# View config content
docker config inspect nginx_config --pretty

Step 3: Update Service to Use Config

Add configs to your service:

```bash # Add config to service docker service update --config-add nginx_config mywebapp

# Add with custom target path docker service update \ --config-add source=nginx_config,target=/etc/nginx/nginx.conf \ mywebapp

# Add with specific permissions docker service update \ --config-add source=nginx_config,target=/etc/nginx/nginx.conf,uid=1000,gid=1000,mode=0644 \ mywebapp ```

Create service with config:

bash
docker service create \
  --name mywebapp \
  --config nginx_config \
  nginx:latest

Step 4: Use Configs in Docker Compose

Define configs in your stack file:

```yaml version: '3.8' configs: nginx_config: external: true # Must exist before deployment

services: web: image: nginx:latest configs: - source: nginx_config target: /etc/nginx/nginx.conf ```

Or create from file:

```yaml version: '3.8' configs: nginx_config: file: ./nginx.conf # Created during deployment

services: web: image: nginx:latest configs: - nginx_config ```

Deploy the stack:

```bash # For external configs, create first docker config create nginx_config ./nginx.conf

# Deploy stack docker stack deploy -c docker-compose.yml myapp

# For file-based configs, just deploy docker stack deploy -c docker-compose.yml myapp ```

Step 5: Update Config Values

Configs are immutable once created. To change a config:

```bash # Create new config version docker config create nginx_config_v2 ./nginx-new.conf

# Update service to use new config docker service update \ --config-rm nginx_config \ --config-add nginx_config_v2 \ mywebapp

# Remove old config docker config rm nginx_config ```

Or use the same name pattern:

```bash # Create with timestamp suffix docker config create nginx_config_$(date +%Y%m%d) ./nginx.conf

# Update service docker service update --config-add nginx_config_20260403 mywebapp ```

Step 6: Remove Unused Configs

Clean up configs no longer in use:

```bash # List configs docker config ls

# Remove unused config docker config rm nginx_config_old

# Cannot remove if in use # Error: config 'nginx_config' is in use by service 'mywebapp' ```

Check config usage:

bash
# Find services using a config
docker service ls --format "{{.Name}}" | while read s; do
  if docker service inspect $s --format '{{range .Spec.TaskTemplate.ContainerSpec.Configs}}{{.ConfigName}}{{"\n"}}{{end}}' | grep -q nginx_config; then
    echo "$s uses nginx_config"
  fi
done

Step 7: Access Configs in Containers

Inside containers, configs appear as files:

```bash # Check config mount location docker exec <container> ls -la /

# For default location docker exec <container> cat /nginx_config

# For custom target docker exec <container> cat /etc/nginx/nginx.conf

# Check file ownership and permissions docker exec <container> ls -la /etc/nginx/nginx.conf ```

Step 8: Debug Config Issues

If services fail due to config problems:

```bash # Check service logs docker service logs mywebapp

# Inspect service task state docker service ps mywebapp --no-trunc

# Look for "config not found" errors docker service inspect mywebapp --format '{{json .Spec.TaskTemplate.ContainerSpec.Configs}}'

# Verify config exists docker config ls | grep nginx_config ```

Step 9: Config vs Secret Decision

Choose between configs and secrets appropriately:

Use Configs forUse Secrets for
nginx.confDatabase passwords
application.ymlAPI keys
JSON configurationTLS certificates
Non-sensitive settingsAuthentication tokens

Both are immutable and require new versions for updates.

Step 10: Multiple Configs per Service

Services can use multiple configs:

bash
docker service create \
  --name myapp \
  --config nginx_config \
  --config app_config \
  --config log_config \
  myimage:latest

In compose:

yaml
services:
  app:
    configs:
      - nginx_config
      - app_config
      - source: log_config
        target: /etc/logging.conf

Complete Config Workflow

```bash # 1. Create config from file docker config create nginx_config ./nginx.conf

# 2. Verify docker config ls docker config inspect nginx_config --pretty

# 3. Create service with config docker service create --name web --config nginx_config nginx

# 4. Verify config in container docker exec $(docker ps -q -f name=web) cat /nginx_config

# 5. Update config (create new version) docker config create nginx_config_v2 ./nginx-updated.conf

# 6. Update service docker service update --config-rm nginx_config --config-add nginx_config_v2 web

# 7. Clean up old config docker config rm nginx_config ```

Common Error Patterns

ErrorCauseFix
config not foundConfig doesn't existCreate config first
config in useCannot remove active configRemove from service first
invalid config referenceWrong config nameUpdate service with correct name

Best Practices

  1. 1.Version configs with meaningful suffixes
  2. 2.Document config changes before updating services
  3. 3.Use configs for non-sensitive data only
  4. 4.Test config changes in staging first
  5. 5.Clean up old config versions periodically

Quick Reference

TaskCommand
List configsdocker config ls
Create configdocker config create NAME file
Inspect configdocker config inspect NAME
View config contentdocker config inspect NAME --pretty
Remove configdocker config rm NAME
Add to servicedocker service update --config-add NAME service
Remove from servicedocker service update --config-rm NAME service

Config errors are resolved by creating the config before deploying services that reference it. Remember configs are immutable—create new versions for updates.