Docker Guide
Overview This guide provides a comprehensive walkthrough for installing Docker on Ubuntu 22.04, migrating the Docker root directory to a data disk, configuring registry mirrors (for regions with internet restrictions), and setting up the NVIDIA Container Toolkit for GPU acceleration. 1. Install Dependencies sudo apt update && sudo apt install -y ca-certificates curl gnupg lsb-release 2. Import Docker GPG Key (Aliyun Mirror) curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/aliyun-docker.gpg 3. Register the Repository echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/aliyun-docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null 4. Install Docker Engine sudo apt update sudo apt install -y docker-ce # Docker starts automatically on Ubuntu. For WSL, use: sudo service docker start 5. Verify Installation sudo docker info 6. Manage Docker as a Non-Root User # Create the docker group if it doesn't exist sudo groupadd docker # Add your user to the group sudo usermod -aG docker $USER # Apply group changes without logging out newgrp docker 7. Operational Cheat Sheet # List all containers (including stopped ones) docker ps -a # List all local images docker images # Debug the Docker daemon (useful if the service fails to start) dockerd # Retag an image docker tag <image-name-1>:<tag-1> <image-name-2>:<tag-2> # Remove an image docker rmi <image-id-or-name> # Follow container logs (Ctrl+C to exit) docker logs -f <container-id> # Inspect container metadata docker inspect <container-id> # Force remove a container docker rm -f <container-id> 8. Migrating the Docker Root Directory To prevent the OS drive from filling up, migrate the storage path to a data disk: ...