Docker在linux系统下的安装

简介: 系统要求本安装教程仅限于CentOS7,其他系统不适用。centos-extras仓库必须是启用状态,这个仓库默认状态是启用,如果不是启用状态,请修改。卸载旧版本的DockerDocker的旧版本叫做docker或者docker-engine。

系统要求

本安装教程仅限于CentOS7,其他系统不适用。
centos-extras仓库必须是启用状态,这个仓库默认状态是启用,如果不是启用状态,请修改。

卸载旧版本的Docker

Docker的旧版本叫做docker或者docker-engine。现在的Docker版本是Docker CE(社区版)和Docker EE(企业版)。一般情况下,咱们使用Docker CE(社区版)就可以了。如果你的系统安装了旧版本,卸载它们以及与它们相关的依赖。命令如下:

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

如果你的系统中没有安装旧版本的Docker,将会出现如下提示:

已加载插件:fastestmirror
参数 docker 没有匹配
参数 docker-client 没有匹配
参数 docker-client-latest 没有匹配
参数 docker-common 没有匹配
参数 docker-latest 没有匹配
参数 docker-latest-logrotate 没有匹配
参数 docker-logrotate 没有匹配
参数 docker-engine 没有匹配
不删除任何软件包

安装Docker

如果你是在主机上第一次安装Docker CE,需要设置Docker的仓库。以后就可以从这个仓库安装和更新Docker了。

设置仓库

  • 安装所需的包,yum-utils提供yum-config-manager工具,device-mapper-persistent-datalvm2devicemapper存储驱动所需要的。安装命令如下:
$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
  • 通过如下的命令设置稳定的仓库
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

安装Docker CE

  • 安装最新版本的Docker CE
$ sudo yum install docker-ce docker-ce-cli containerd.io

命令完成后,Docker已经安装,但是并没有启动。

  • 启动Docker
$ sudo systemctl start docker
  • 通过运行hello-world镜像验证Docker CE是否安装成功。
$ sudo docker run hello-world

运行结果如下:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e
Status: Downloaded newer image for hello-world:latest

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的卸载

  • 卸载Docker包
$ sudo yum remove docker-ce
  • 镜像、容器、自定义配置文件等并不会随着Docker的卸载自动删除,你需要执行一下命令手动删除:
$ sudo rm -rf /var/lib/docker

到这里,Docker的安装与卸载过程就给大家介绍完了。

目录
相关文章
|
4天前
|
资源调度 JavaScript 搜索推荐
Linux系统之部署envlinks极简个人导航页
【4月更文挑战第11天】Linux系统之部署envlinks极简个人导航页
30 2
|
6天前
|
缓存 Linux 测试技术
安装【银河麒麟V10】linux系统--并挂载镜像
安装【银河麒麟V10】linux系统--并挂载镜像
43 0
|
6天前
|
监控 Unix Linux
Linux操作系统调优相关工具(四)查看Network运行状态 和系统整体运行状态
Linux操作系统调优相关工具(四)查看Network运行状态 和系统整体运行状态
21 0
|
6天前
|
Linux C语言
linux yum安装ffmpeg 图文详解
linux yum安装ffmpeg 图文详解
23 0
|
6天前
|
NoSQL Linux Redis
linux 下和win下安装redis 并添加开机自启 图文详解
linux 下和win下安装redis 并添加开机自启 图文详解
13 0
|
6天前
|
Linux
linux yum 安装rar和unrar
linux yum 安装rar和unrar
27 0
|
13天前
|
存储 前端开发 Linux
Linux系统之部署ToDoList任务管理工具
【4月更文挑战第1天】Linux系统之部署ToDoList任务管理工具
60 1
|
4天前
|
存储 算法 Linux
【实战项目】网络编程:在Linux环境下基于opencv和socket的人脸识别系统--C++实现
【实战项目】网络编程:在Linux环境下基于opencv和socket的人脸识别系统--C++实现
17 6
|
3天前
|
测试技术 Linux 数据安全/隐私保护
【Docker项目实战】使用Docker部署Seatsurfing预订座位系统
【4月更文挑战第12天】使用Docker部署Seatsurfing预订座位系统
12 3
|
4天前
|
时序数据库 Docker 容器
Docker安装InfluxDB
Docker安装InfluxDB
8 0