Install or restore Docker on Debian 12
Here's a single block of commands to install Docker on Debian 12 and set the Docker container directory to /media/disk8/var/lib/docker
without touching existing containers:
# Update package list and install required packages
sudo apt-get update -y && sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
# Add Docker’s official GPG key and set up the stable repository
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update package list and install Docker
sudo apt-get update -y && sudo apt-get install -y docker-ce docker-ce-cli containerd.io
# Stop Docker services to update the directory
sudo systemctl stop docker
# Configure Docker to use /media/disk8/var/lib/docker as its data directory
sudo mkdir -p /media/disk8/var/lib/docker
sudo tee /etc/docker/daemon.json <<EOF
{
"data-root": "/media/disk8/var/lib/docker"
}
EOF
# Restart Docker to apply changes
sudo systemctl start docker
sudo systemctl enable docker
This will install Docker, configure the data directory as specified, and ensure the configuration is applied without affecting existing containers in /media/disk8/var/lib/docker
.