# Docker安装

# 系统准备

cat /etc/issue
Ubuntu 22.04.4 LTS

Ubuntu

# 关闭防火墙

ufw disable
ufw status

Ubuntu

# 关闭swap

vi /etc/fstab

Ubuntu

最好重启一下机器,然后下一步安装docker

# 验证swap

swapon --show
free -m

Ubuntu

# 安装

# 官网文档

https://docs.docker.com/engine/install/ubuntu/ (opens new window)

# 移除旧的pkg

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

# proxy(可选)

export https_proxy=http://xx.xx.xx.xx:xx  
export http_proxy=http://xx.xx.xx.xx:xx 
export proxy=http://xx.xx.xx.xx:xx   
export all_proxy=socks5://xx.xx.xx.xx:xx 
export HTTPS_PROXY=http://xx.xx.xx.xx:xx  
export HTTP_PROXY=http://xx.xx.xx.xx:xx 
export PROXY=http://xx.xx.xx.xx:xx   
export ALL_PROXY=socks5://xx.xx.xx.xx:xx 

curl https://hub.docker.com/explore
unset https_proxy
unset http_proxy
unset proxy
unset no_proxy
unset proxy
unset HTTPS_PROXY
unset HTTP_PROXY
unset PROXY
unset ALL_PROXY
unset NO_PROXY
curl https://hub.docker.com/explore

env | grep "proxy"
env | grep "PROXY"

# 配置apt-get

# Add Docker's official GPG key:
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

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

# 安装docker

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# docker info

docker info

docker

# 验证

# 运行hello-world

sudo docker run --rm  hello-world

hello-world

# Environment PROXY(可选)

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf <<-'EOF'
[Service]
Environment="HTTP_PROXY=http://xx.xx.xx.xx:xx "
Environment="HTTPS_PROXY=http://xx.xx.xx.xx:xx "
EOF
sudo systemctl show --property=Environment docker

# 镜像加速器registry-mirrors(可选)

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxxxxxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker