当前位置: 首页 > 工具软件 > docker-amd > 使用案例 >

centos7安装docker和docker-compose

朱宜
2023-12-01

1. 安装docker

$ yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
  
$ yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
    
yum list docker-ce --showduplicates | sort -r

已加载插件:fastestmirror, langpacks
可安装的软件包
 * updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile
 * extras: mirrors.aliyun.com
docker-ce.x86_64            3:19.03.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.0-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.9-3.el7                     docker-ce-stable
...

选择安装一个版本

yum install docker-ce-20.10.18-3.el7 -y

启动 Docker

systemctl start docker
systemctl enable docker

配置 Docker 镜像加速器

cat <<EOF> /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "registry-mirrors": ["https://x83mabsk.mirror.aliyuncs.com"]
}
EOF

# 生效
systemctl daemon-reload
systemctl restart docker

测试

[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.18
 API version:       1.41
 Go version:        go1.18.6
 Git commit:        b40c2f6
 Built:             Thu Sep  8 23:14:08 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.18
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.6
  Git commit:       e42327a
  Built:            Thu Sep  8 23:12:21 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

2. 安装docker-compose

查看最新版 https://github.com/docker/compose/releases

运行此命令以下载Docker Compose的当前稳定版本

curl -L "https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  • 要安装不同版本的Compose,请替换v2.10.2 为要使用的Compose版本
  • 如果github下载失败,可以科学上网下载后上传到服务器,安装yum install lrzsz -y,然后rz上传文件,然后mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose

对二进制文件应用可执行权限

chmod +x /usr/local/bin/docker-compose

测试

[root@localhost ~]# docker-compose --version
Docker Compose version v2.10.2
 类似资料: