fix(docker): write valid /etc/docker/daemon.json and add optional data-root properly

This commit is contained in:
Mărcziem ™
2025-10-03 12:28:30 +02:00
parent f106f966a3
commit 2593b6f8fe

View File

@@ -156,35 +156,37 @@ configure_docker_daemon() {
sudo mkdir -p /etc/docker sudo mkdir -p /etc/docker
# Create optimized daemon.json # Create optimized daemon.json with optional data-root
cat << EOF | sudo tee /etc/docker/daemon.json local _data_root_line=""
if [[ "$DOCKER_DATA_DIR" != "${DEFAULT_DOCKER_DATA_DIR}" ]]; then
_data_root_line=" \"data-root\": \"${DOCKER_DATA_DIR}\","
log_debug "Including data-root in daemon.json: ${DOCKER_DATA_DIR}"
fi
sudo tee /etc/docker/daemon.json > /dev/null <<EOF
{ {
"storage-driver": "overlay2", ${_data_root_line}
"log-driver": "json-file", "storage-driver": "overlay2",
"log-opts": { "log-driver": "json-file",
"max-size": "10m", "log-opts": {
"max-file": "3" "max-size": "10m",
}, "max-file": "3"
"exec-opts": ["native.cgroupdriver=systemd"], },
"live-restore": true, "exec-opts": ["native.cgroupdriver=systemd"],
"userland-proxy": false, "live-restore": true,
"experimental": false, "userland-proxy": false,
"metrics-addr": "0.0.0.0:9323", "experimental": false,
"default-ulimits": { "metrics-addr": "0.0.0.0:9323",
"nofile": { "default-ulimits": {
"Hard": 64000, "nofile": {
"Name": "nofile", "Name": "nofile",
"Soft": 64000 "Soft": 64000,
"Hard": 64000
}
} }
} }
EOF EOF
# Add data-root if custom directory is specified
if [[ "$DOCKER_DATA_DIR" != "$DEFAULT_DOCKER_DATA_DIR" ]]; then
# Modify the daemon.json to include data-root
sudo sed -i "s|{|{\n \"data-root\": \"$DOCKER_DATA_DIR\",|" /etc/docker/daemon.json
fi
# Restart Docker to apply configuration # Restart Docker to apply configuration
handle_error sudo systemctl restart docker handle_error sudo systemctl restart docker