本文介绍在多种系统中的Docker安装方式
当然你也可以直接参考官方文档
1. 安装Docker
任何架构任何系统版
#安装
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
#启动
systemctl enable docker
systemctl start docker
#修改配置
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
#此处指定docker的数据卷目录,请根据自己的磁盘挂载情况配置
"data-root": "/opt/docker",
"registry-mirrors": [
"https://3laho3y3.mirror.aliyuncs.com",
"https://hub-mirror.c.163.com",
"http://f1361db2.m.daocloud.io",
"http://hub-mirror.c.163.com"
]
}
EOF
#重启
sudo systemctl daemon-reload
systemctl restart docker
#测试
docker run hello-world
CentOS
#安装依赖
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
#指定镜像源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#安装docker,可替换需要的版本,默认为最新版本,仓库地址:https://download.docker.com/linux/centos/7/aarch64/stable/Packages/
sudo yum install -y docker-ce containerd.io docker-ce-cli
#启动
systemctl enable docker
systemctl start docker
#修改配置
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"data-root": "/opt/docker",
"registry-mirrors": [
"https://3laho3y3.mirror.aliyuncs.com",
"https://hub-mirror.c.163.com",
"http://f1361db2.m.daocloud.io",
"http://hub-mirror.c.163.com"
]
}
EOF
#重启
sudo systemctl daemon-reload
systemctl restart docker
#测试
docker run hello-world
Ubuntu(Arm64)
# 移除旧版本(非必须)
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=arm64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
systemctl enable docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"data-root": "/opt/lib/docker",
"registry-mirrors": [
"https://3laho3y3.mirror.aliyuncs.com",
"https://hub-mirror.c.163.com",
"http://f1361db2.m.daocloud.io",
"http://hub-mirror.c.163.com"
]
}
EOF
#重启
sudo systemctl daemon-reload
systemctl restart docker
#测试
docker run hello-world
Ubuntu(x86)
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
systemctl enable docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"data-root": "/opt/lib/docker",
"registry-mirrors": [
"https://3laho3y3.mirror.aliyuncs.com",
"https://hub-mirror.c.163.com",
"http://f1361db2.m.daocloud.io",
"http://hub-mirror.c.163.com"
]
}
EOF
#重启
sudo systemctl daemon-reload
systemctl restart docker
2. 安装 Docker-Compose
arm架构参照华为文档安装Docker Compose
x86
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose