Skip to content

Instantly share code, notes, and snippets.

@DamichiXL
Last active September 27, 2024 12:57
Show Gist options
  • Save DamichiXL/514e10a78ad19286cd9289ff228d07c5 to your computer and use it in GitHub Desktop.
Save DamichiXL/514e10a78ad19286cd9289ff228d07c5 to your computer and use it in GitHub Desktop.
Update docker configuration - mount to custom mountpoint
#!/bin/bash
echo "Stopping docker services"
systemctl stop docker.service
systemctl stop docker.socket
echo "Stopped"
DATA_ROOT="/home/docker"
FILE="/lib/systemd/system/docker.service"
SEARCH_LINE="^ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock"
REPLACE_LINE="ExecStart=/usr/bin/dockerd -H fd:// --data-root $DATA_ROOT --containerd=/run/containerd/containerd.sock"
# Check if the file exists
if [[ -f "$FILE" ]]; then
# Use sed to replace the line
sed -i "s|$SEARCH_LINE|$REPLACE_LINE|" "$FILE"
echo "Updated ExecStart in $FILE"
else
echo "File $FILE does not exist."
fi
echo "Removing files from /var/lib/docker"
rm -rf /var/lib/docker
echo "Reloading daemon"
systemctl daemon-reload
echo "Start docker services"
systemctl start docker
echo "--Finished--"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment