CentOS docker 和 docker compose 安装

CentOS docker 和 docker compose 安装

博主博客

Docker 是一个用于开发,交付和运行应用程序的开放平台。Compose 是用于定义和运行多容器 Docker 应用程序的工具。通过 Compose,您可以使用 YML 文件来配置应用程序需要的所有服务。

卸载

1. 卸载旧版本

如果之前已经安装过 docker 或者 docker-engine 可以先卸载

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

2. 卸载 docker

yum remove docker-ce

3. 删除镜像、容器、配置文件等

rm -rf /var/lib/docker

4. 卸载 docker-compose

sudo rm /usr/local/bin/docker-compose

一、安装 docker

1. 一键安装

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

如果安装失败, 可以使用国内 daocloud 一键安装

curl -sSL https://get.daocloud.io/docker | sh

2. 启动服务

sudo systemctl restart docker

3. 测试

docker run hello-world

通过运行 hello-world 镜像来验证是否已经成功安装 Docker

输出下面信息, 表示成功安装。

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

二、安装 docker compose

1. 可以通过 Github 查看最新的发行版本

https://github.com/docker/compose/releases

2. 一键安装

把下面命令的 x.x.x 修改为需要安装的版本。

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

如果安装失败, 可以使用国内 daocloud 一键安装

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

也可以通过 fastgit 一键安装

sudo curl -L https://download.fastgit.org/docker/compose/releases/download/vx.x.x/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
  1. 增加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
  1. 测试
docker-compose --version

输出 Docker Compose version v2.13.0 即安装成功。

猜你喜欢

转载自blog.csdn.net/dxk539687357/article/details/128095941
今日推荐