您的当前位置:首页正文

linux安装docker和docker compose

2024-11-28 来源:个人技术集锦

docker安装必须要求Linux内核版本在3.10以上查看内核版本命令

uname -r

1.卸载旧版

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

2.安装docker所依赖的包

yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

3.设置稳定的仓库

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

4.安装最新 docker引擎

yum install docker-ce docker-ce-cli containerd.io

5.启动docker

systemctl start docker

6.查看是否安装成功

docker -v

6.1设置开机启动
7.安装docker compose(统一管理多个Docker容器)
国内高速镜像安装:

curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

github安装:

curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

7.1对二进制文件授予可执行权限

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

7.2创建link

ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

7.3查询是否安装成功

docker-compose -v

8.设置ustc镜像(镜像加速器)
8.1编辑或新增

vim /etc/docker/daemon.json

将下面内容copy到文件内

{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}

8.2重启docker服务

systemctl restart docker
显示全文