Skip to content
SumGuy's Ramblings
Go back

Understanding and Optimizing Docker’s daemon.json File

Introduction

The daemon.json file is a crucial configuration file for Docker that allows administrators to customize various aspects of the Docker daemon’s behavior. In this article we will explore the purpose of this file, common configuration options, and best practices for optimizing Docker performance and security.

The Need for daemon.json

The daemon.json file serves several important purposes:

Location and Format

On Linux systems, the daemon.json file is typically located at /etc/docker/daemon.json. If it doesn’t exist, you can create it. The file uses JSON format, which is easy to read and modify.

Rootless Docker Configuration

When using rootless Docker, the location of the daemon.json file is different. For rootless mode, the configuration file is located at ~/.config/docker/daemon.json in the user’s home directory. This separate location ensures that rootless Docker configurations don’t interfere with system-wide Docker settings and allows individual users to have their own custom Docker daemon configurations. Remember to create this file if it doesn’t exist, and ensure it has the correct permissions for the user running rootless Docker.

Common Configuration Options

Let’s explore some common options that can be set in the daemon.json file, along with their purposes and examples:

1. Storage Driver

{
  "storage-driver": "overlay2"
}

2. Live Restore

{
  "live-restore": true
}

3. DNS Settings

{
  "dns": ["8.8.8.8", "1.1.1.1"]
}

4. Logging

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

5. Registry Mirrors

{
  "registry-mirrors": ["https://mirror.gcr.io"]
}

6. Insecure Registries

{
  "insecure-registries": ["myregistry.example.com:5000"]
}

7. Default Address Pools

{
  "default-address-pools": [
    {"base":"172.80.0.0/16","size":24},
    {"base":"172.90.0.0/16","size":24}
  ]
}

My Production Configuration

Now, let’s examine the configuration I use in my production machines and discuss why these settings make sense for a production environment:

{
  "storage-driver": "overlay2",
  "live-restore": true,
  "dns": ["9.9.9.10", "1.1.1.1", "8.8.8.8"],
  "max-concurrent-downloads": 5,
  "max-concurrent-uploads": 5,
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "5m",
    "max-file": "3"
  }
}

Whats in this Configuration:

This configuration in my opinion demonstrates a focus on performance, stability, and efficient resource management, which are crucial in a production environment.

Best Practices

Conclusion

The daemon.json file is a powerful tool for customizing Docker’s behavior to suit your specific needs. By understanding the available options and following best practices, you can optimize Docker’s performance, security, and resource usage in your environment. Regular review and thoughtful configuration of this file can significantly enhance your Docker experience, whether you’re a system administrator, DevOps professional, or developer.


Share this post on:

Previous Post
SSHFS: Ditch SCP & Access Remote Files
Next Post
Techniques for Writing Robust, Reliable Bash Scripts