Linux环境中安装docker

1. 卸载旧版本

如果你此前已经安装过docker engine,那么这步是必须的,请使用以下的命令删除历史安装:

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

如果yum包管理器回复未安装,那么这不会影响到之后的安装。
这里需要注意,卸载docker时,存储在 /var/lib/docker/目录下的镜像,容器,卷和网络并不会自动删除。

2. 安装方式选择

2.1. 设置存储库

安装需要的软件包并设置 Docker 的存储库,使用以下命令。

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

2.2. 安装Docker engine

安装 Docker engine、containerd和docker compose
要安装最新的版本,运行以下命令:

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

这个命令安装了Docker,但是并不会启动Docker。同时它还会创建Docker组,默认情况下并不会向该组添加任何用户。
如果你需要安装特定版本,这在很多时候都是被要求执行的。
首先需要列出存储库中的可用版本,使用以下命令:

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

返回的列表中显示了软件包的版本,安装特定版本时需要指定包名称加上版本字符串。将 <VERSION_STRING>替换为所需的版本,执行以下命令:

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

2.3. 启动docker

sudo systemctl start docker
我们可用通过运行镜像来验证安装是否成功:

sudo docker run hello-world
此命令将下载测试镜像并在容器中运行,当容器运行,它会打印确认信息并退出。

显示如下:

[root@localhost ~]# 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/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值