Skip to main content

首页 / Posts

[Docker] Escape Environment-Setup Nightmares: A Beginner Installation Guide

A 2025 beginner-focused Docker installation guide covering Windows with WSL2, macOS on Apple Silicon or Intel, Linux, mirror acceleration, verification commands, and first-container testing.

Rosetears·
··875 words·5 mins

1. Why do we need Docker?
#

Before diving into commands, it is worth clarifying what Docker is. In simple terms, Docker is like a standardized magic container. It packages your application together with everything it needs: code, runtime libraries, environment variables, configuration files, and dependencies.

Move that container to a Windows laptop, a colleague’s Mac, or a Linux server, and the application should run the same way. The classic complaint “it works on my machine” becomes much less frequent.

For developers and beginners, Docker offers immediate benefits:

  • Escape environment-setup nightmares: deploy complex applications without fighting dependency conflicts.
  • Keep the host system clean: development environments stay isolated in containers.
  • Share and collaborate easily: others can run the same project without manual setup.
  • Step into cloud native: Docker is the first stop toward Kubernetes, microservices, and modern deployment.

Video walkthrough: Docker installation guide


2. Download channels and version information
#

Download Docker from official sources whenever possible:


3. Installation steps
#

Windows 11: Docker Desktop
#

  1. Enable virtualization and WSL 2. Check virtualization in Task Manager, then run WSL commands in administrator PowerShell if needed.
  2. In Windows Features, enable Virtual Machine Platform and Windows Subsystem for Linux.
  3. Download Docker Desktop Installer.exe from the official site and keep Use WSL 2 instead of Hyper-V (recommended) selected.
  4. Launch Docker Desktop, accept the subscription service agreement, and wait until the whale icon is steady.

macOS: Docker Desktop
#

Download the .dmg for Intel or Apple Silicon, drag Docker into Applications, open it, and approve the requested permissions. Homebrew users can also install with brew install --cask docker. Apple Silicon users who need x86-only images may install Rosetta 2.

Linux: Docker Engine
#

Remove old conflicting packages, add Docker’s official GPG key and apt repository, then install docker-ce, docker-ce-cli, containerd.io, Buildx, and Compose. Start and enable the service with systemctl.


4. Verify the environment
#

Run docker run hello-world. If you see Hello from Docker!, image download and container execution are working. docker info shows version, storage driver, image/container counts, and is useful for troubleshooting.


5. Configure registry mirrors
#

By default, docker pull downloads from Docker Hub and may be slow in some networks. Configure mirrors in Docker Desktop under Settings → Docker Engine by adding a registry-mirrors array, then click Apply & Restart. On Linux, edit /etc/docker/daemon.json, add the same mirror list, and restart Docker.


6. Change default resource paths
#

On Windows, Docker or IDE resources stored on the system drive can hit permission or space issues. In Docker Desktop, open Settings → Resources, choose Browse, select a non-system drive such as D:\Docker_Resources, and click Apply & Restart. Prefer a fast SSD partition for better I/O.


7. Uninstalling and upgrading
#

Uninstalling Docker can remove local images, containers, volumes, and networks, so back up important data first. Docker Desktop can be removed from Windows Apps or the macOS troubleshooting menu. On Ubuntu, purge Docker packages and remove /var/lib/docker and /var/lib/containerd if you really want a clean uninstall.

Docker Desktop includes automatic updates. Docker Engine installed through apt can be upgraded with normal package updates.

Recommended video#

Docker: escape environment setup nightmares

Screenshots and media
#

可选功能图片
Resources 路径配置界面

Preserved command, configuration, and prompt blocks
#

1
2
3
4
5
6
7
     wsl --install           # 首次安装
     wsl --set-default-version 2
     wsl --update --web-download           # 已安装用户更新内核
     ```

```bash
   /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
1
   softwareupdate --install-rosetta --agree-to-license
1
   brew install --cask docker
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
     brew upgrade --cask docker
     ```

```bash
     brew uninstall --cask docker
     ```

```bash
# 编者注:此命令会安全地尝试移除所有已知的旧版或冲突包。
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
sudo apt-get autoremove -y
1
2
sudo apt-get update
sudo apt-get install ca-certificates curl
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 添加 Docker 官方 GPG 密钥:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# 添加 Docker 仓库:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo \"$UBUNTU_CODENAME\") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
1
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
1
2
sudo systemctl start docker # 启动
sudo systemctl enable docker # 开机自启动
1
docker run hello-world
1
docker info
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
{
 "registry-mirrors": [
"https://docker.xuanyuan.me",
"https://docker.1ms.run",
"https://dislabaiot.xyz",
"https://doublezonline.cloud",
"https://xdark.top",
"https://docker.m.daocloud.io",
"https://elastic.m.daocloud.io",
"https://gcr.m.daocloud.io",
"https://ghcr.m.daocloud.io",
"https://k8s-gcr.m.daocloud.io",
"https://k8s.m.daocloud.io",
"https://mcr.m.daocloud.io",
"https://nvcr.m.daocloud.io",
"https://quay.m.daocloud.io",
"https://ollama.m.daocloud.io"
 ]
}
1
sudo nano /etc/docker/daemon.json
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
{
 "registry-mirrors": [
"https://docker.xuanyuan.me",
"https://docker.1ms.run",
"https://dislabaiot.xyz",
"https://doublezonline.cloud",
"https://xdark.top",
"https://docker.m.daocloud.io",
"https://elastic.m.daocloud.io",
"https://gcr.m.daocloud.io",
"https://ghcr.m.daocloud.io",
"https://k8s-gcr.m.daocloud.io",
"https://k8s.m.daocloud.io",
"https://mcr.m.daocloud.io",
"https://nvcr.m.daocloud.io",
"https://quay.m.daocloud.io",
"https://ollama.m.daocloud.io"
 ]
}
1
sudo systemctl restart docker
1
2
3
4
5
6
# 1. 卸载所有相关包
sudo apt-get purge -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo apt-get autoremove -y --purge
# 2. 删除所有数据
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
1
2
sudo apt-get update
sudo apt-get install -y --only-upgrade docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Related

[Installation] Install R, RStudio, and RTools

··625 words·3 mins
This article explains how to download and install R, RTools, and RStudio, including choosing a suitable CRAN mirror, configuring the correct installation path, and setting environment variables so you can set up an R development environment easily.