CentOS Docker 安装

CentOS安装Docker-CE

官方安装教程:https://docs.docker.com/engine/install/centos/

Docker 支持 64 位 CentOS 7 以上 的版本

1.卸载旧版本的Docker

如果以前安装过旧版的 docker, 先删除旧版的 docker (旧版的docker叫:docker or docker-engine )。新版的 docker 叫:docker-ce, 全称:Docker Engine-Community

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies

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

2.用 Docker 仓库进行安装

官网推荐的一种安装方式

在新主机上首次安装 Docker Engine-Community 之前,需要设置 Docker 仓库。之后,您可以从仓库安装和更新 Docker。

1.设置仓库

安装所需的软件包。yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2。
1.安装yum-utils依赖包

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

2.开始设置docker仓库

docker 官网仓库


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

阿里云仓库( 推荐 )

sudo yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

执行整个命令之后,在 /etc/yum.repos.d 路径下就会多出一个 docker-ce.repo yum源文件

2.安装最新的Docker E-C

Install the latest version of Docker Engine and containerd

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

docker 安装到:/var/lib/docker/ 目录下

3.安装指定版本的Docker E-C

1、列出并排序您存储库中可用的版本。此示例按版本号(从高到低)对结果进行排序。

$ yum list docker-ce --showduplicates | sort -r

docker-ce.x86_64  3:18.09.1-3.el7                     docker-ce-stable
docker-ce.x86_64  3:18.09.0-3.el7                     docker-ce-stable
docker-ce.x86_64  18.06.1.ce-3.el7                    docker-ce-stable
docker-ce.x86_64  18.06.0.ce-3.el7                    docker-ce-stable

2、通过其完整的软件包名称安装特定版本,该软件包名称是软件包名称(docker-ce)加上版本字符串(第二列),从第一个冒号(:)一直到第一个连字符,并用连字符(-)分隔。例如:docker-ce-18.09.1。

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

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

docker 安装到:/var/lib/docker/ 目录下

4.启动Docker

sudo systemctl start docker

启动docker之后便可以使用docker的命令

关闭docker: sudo systemctl stop docker
重启docker: sudo systemctl restart docker

5.验证是否安装成功

sudo docker run hello-world


[root@VM_0_6_centos yum.repos.d]# docker run hello-world

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/

6.卸载Docker-CE

1.Uninstall the Docker Engine, CLI, and Containerd packages:

$ sudo yum remove docker-ce docker-ce-cli containerd.io

2.Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:

 sudo rm -rf /var/lib/docker
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值