Ubuntu系统Docker添加daemon.json文件及解决文件不存在报错
daemon.json for Docker on Ubuntu Hey there! That error makes total sense—you're trying to reference a file that doesn't exist yet. Let's walk through creating and setting up /etc/docker/daemon.json properly:
Step 1: Create the daemon.json file
First, we'll create the file in the correct directory. You can jump straight into editing it with a simple text editor like nano (this will create the file if it doesn't exist):
sudo nano /etc/docker/daemon.json
Step 2: Add your Docker daemon configuration
Next, add your desired settings to the blank file. This is where you can configure things like registry mirrors (for faster image pulls), storage drivers, or other daemon behaviors. Here's a common example to get you started:
{ "registry-mirrors": ["https://your-preferred-mirror.example.com"], "storage-driver": "overlay2" }
Adjust or add other settings based on your needs—just make sure the JSON syntax is valid (no trailing commas, properly nested brackets).
Step 3: Save and exit the editor
In nano, press Ctrl+O to save the file, hit Enter to confirm the filename, then Ctrl+X to exit the editor.
Step 4: Apply the configuration
Now we need to reload the Docker daemon and restart the service to pick up the new settings:
sudo systemctl daemon-reload sudo systemctl restart docker
Step 5: Verify the configuration works
To confirm Docker is using your new daemon.json settings, run:
docker info
Look for sections like Registry Mirrors or Storage Driver in the output—they should match what you set in the file.
Quick note about the dockerd --config-file command
You don't usually need to run dockerd with the --config-file flag manually. Docker automatically checks /etc/docker/daemon.json by default when starting up. If you do want to use that flag for testing, just ensure the file exists first (which we've now created!) and run it with sudo:
sudo dockerd --config-file /etc/docker/daemon.json
内容的提问来源于stack exchange,提问作者Ravi

