centos安装docker、一键安装docker

发布时间:2022-03-01 09:52:29 作者:yexindonglai@163.com 阅读(725)

前言

本文章是根据官网安装流程而来,经过自行试验完全可行,英语功底好或者精通翻译软件的童鞋完全可以参照官网进行安装!

说明

官网提示安装docker需要centos7以上的版本才可以安装;在安装时最好使用root最高权限进行安装,如果是普通用户,那么就需要在安装命令前面加上sudo来使用管理员权限;

docker运行镜像流程图

在这里插入图片描述

一、安装(第一种方式:官网教程)

1、卸载旧版本

安装之前需要先卸载旧版本的docker,以确保不会冲突, 这里卸载的是所有的和docker相关的软件,有docker-client(客户端)、docker-engine(引擎)

  1. yum remove docker \
  2. docker-client \
  3. docker-client-latest \
  4. docker-common \
  5. docker-latest \
  6. docker-latest-logrotate \
  7. docker-logrotate \
  8. docker-engine

2、安装docker环境和工具包

  1. # 安装需要依赖的工具包
  2. yum install -y yum-utils
  3. # 设置镜像仓库--默认是国外的,非常慢,不建议使用
  4. yum-config-manager \
  5. --add-repo \
  6. https://download.docker.com/linux/centos/docker-ce.repo
  7. # 使用国内的阿里云镜像仓库-- 比较快 ,建议使用这个
  8. yum-config-manager \
  9. --add-repo \
  10. http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3、安装 Docker 引擎

  • docker-ce: 表示是社区版本,docker-ee为企业版,对我们学习来说,社区版已经够用了;
  • containerd.io :docker的容器
  1. # 未加版本号表示安装的是目前最新版本的docker
  2. yum install \
  3. docker-ce docker-ce-cli containerd.io -y
  4. # 如果需要安装指定版本的docker,可以在后面加上版本号
  5. yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

4、 启动docker

启动docker有2种方式,建议使用第二种

  1. # 第一种:启动docker
  2. systemctl start docker
  3. # 第二种:启动docker并设为开机启动
  4. systemctl enable docker --now

5、运行hello-world 镜像来验证 Docker Engine 是否已正确安装。

  1. docker run hello-world

运行后会弹出一些信息,我们一步步解析下,里面的信息都是啥意思

  1. [root@VM_0_5_centos ~]# docker run hello-world
  2. Unable to find image 'hello-world:latest' locally
  3. latest: Pulling from library/hello-world
  4. 2db29710123e: Pull complete
  5. Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
  6. Status: Downloaded newer image for hello-world:latest
  7. Hello from Docker!
  8. This message shows that your installation appears to be working correctly.
  9. To generate this message, Docker took the following steps:
  10. 1. The Docker client contacted the Docker daemon.
  11. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  12. (amd64)
  13. 3. The Docker daemon created a new container from that image which runs the
  14. executable that produces the output you are currently reading.
  15. 4. The Docker daemon streamed that output to the Docker client, which sent it
  16. to your terminal.
  17. To try something more ambitious, you can run an Ubuntu container with:
  18. $ docker run -it ubuntu bash
  19. Share images, automate workflows, and more with a free Docker ID:
  20. https://hub.docker.com/
  21. For more examples and ideas, visit:
  22. https://docs.docker.com/get-started/

a、首先我们看看这一行内容,这个意思是告诉我们找不到hello-world的镜像;

  1. Unable to find image 'hello-world:latest' locally

b、第二步自动从仓库将hello-world的镜像拉去下来

  1. latest: Pulling from library/hello-world

c、拉取完成了

  1. 2db29710123e: Pull complete

d、验证镜像签名信息

  1. Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51

e、验证签名信息成功,代表拉取ok了

  1. Status: Downloaded newer image for hello-world:latest

f、当展示这一行的话就代表docker已经安装成功了

  1. Hello from Docker!

二、安装(第二种方式:一键安装)

Ubuntu、Debian、UOS、Deepin、CentOS都一样

1、下载docker

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

等待安装完成后,运行docker ps,这样就算是安装好了

2、启动服务

  1. systemctl start docker.service

3、开机自启

  1. sudo systemctl enable docker

三、完

关键字Docker