安装Docker

由于每个系统所需要执行的命令都不一样,请看官方文档地址:https://docs.docker.com/engine/install

  • Debian安装命令
sudo apt update

sudo apt install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release 

sudo mkdir -p /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
  • CentOS安装命令
sudo yum install -y yum-utils

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
  • Ubuntu安装命令

使用apt安装

apt install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

apt update
apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y

使用snap安装(不推荐)

sudo snap install docker -y
# 这行命令会自动安装docker和docker-compose

安装Docker Compose

方法一、通过下载二进制文件安装

需要到GitHub上下载最新的二进制文件

官网链接:https://github.com/docker/compose/releases

image-20220621104431822

服务器的话一般选择带有linux x86_64字样的发行版软件

将它下载下来然后上传到服务器上

然后执行下列命令

# 修改文件名称并移动到bin目录下
sudo mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
# 赋予执行权限
sudo chmod +x /usr/local/bin/docker-compose
# 检查是否安装成功
docker-compose -v
# 输出:Docker Compose version v2.6.0 即表示安装成功

方法二、通过pip安装

sudo pip install docker-compose

Docker换源

如果你的服务器没有连接到世界,那么拉取镜像的速度可能会很慢,甚至出现无法拉取镜像的情况
这时你可以尝试更换镜像源,可以看我的这篇文章操作:https://www.hash070.top/archives/docker-change-mirror.html

Q.E.D.