Docker在linux系统下的安装

系统要求

本安装教程仅限于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的安装与卸载过程就给大家介绍完了。

猜你喜欢

转载自www.cnblogs.com/boboooo/p/10820493.html