环境准备

操作系统需求

为兼容企业级应用,学习选用Centos7做为部署安装Docker的系统平台

  1. # 通过以下命令可查看系统版本和内核版本等信息
  2. cat /etc/redhat-release
  3. #-----------------------------------
  4. CentOS Linux release 7.4. (Core)
  5. #-----------------------------------
  6.  
  7. uname -a
  8. #---------------------------------------------------------------------------------------------------------
  9. Linux docker01 3.10.-.el7.x86_64 # SMP Tue Aug :: UTC x86_64 x86_64 x86_64 GNU/Linux
  10. #---------------------------------------------------------------------------------------------------------
  11.  
  12. cat /etc/os-release
  13. #------------------------------------------
  14. NAME="CentOS Linux"
  15. VERSION="7 (Core)"
  16. ID="centos"
  17. ID_LIKE="rhel fedora"
  18. VERSION_ID=""
  19. PRETTY_NAME="CentOS Linux 7 (Core)"
  20. ANSI_COLOR="0;31"
  21. CPE_NAME="cpe:/o:centos:centos:7"
  22. HOME_URL="https://www.centos.org/"
  23. BUG_REPORT_URL="https://bugs.centos.org/"
  24.  
  25. CENTOS_MANTISBT_PROJECT="CentOS-7"
  26. CENTOS_MANTISBT_PROJECT_VERSION=""
  27. REDHAT_SUPPORT_PRODUCT="centos"
  28. REDHAT_SUPPORT_PRODUCT_VERSION=""
  29. #------------------------------------------

更换默认的yum源

Centos默认的yun源在国外,速度很慢有时间也无法访问

 
  1. yum repolist
  2. #------------------------------------------------------------------------------------------------------------------------------
  3. Loaded plugins: fastestmirror
  4. Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
  5. : curl# - "Could not resolve host: mirrorlist.centos.org; Unknown error"
  6. Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
  7. : curl# - "Could not resolve host: mirrorlist.centos.org; Unknown error"
  8. Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
  9. : curl# - "Could not resolve host: mirrorlist.centos.org; Unknown error"
  10. repo id repo name status
  11. base//x86_64 CentOS- - Base
  12. extras//x86_64 CentOS- - Extras
  13. updates//x86_64 CentOS- - Updates
  14. repolist:
  15. #------------------------------------------------------------------------------------------------------------------------------
  16.  
  17. # 公司内服务器域名解析总有问题,时好时不好,很烦,这里直接用hosts做解析
  18. vi /etc/hosts
  19. #-------------------------------------
  20. 221.206.129.236 mirrors.aliyun.com
  21. #-------------------------------------
  22.  
  23. # 更换成aliyun yum源
  24. cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
  25. curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  26.  
  27. # 编译CentOS-Base.repo,把带mirrors.aliyuncs.com的行都删除
  28. vi /etc/yum.repos.d/CentOS-Base.repo
  29.  
  30. # 运行以下命令生成缓存
  31. yum clean all
  32. yum makecache
  33.  
  34. # 查看已启用的repo,确保centos-extras repository是启用了,安装docker时需要
  35. yum repolist
  36. #--------------------------------------------------------------------------
  37. Loaded plugins: fastestmirror
  38. Loading mirror speeds from cached hostfile
  39. * base: mirrors.aliyun.com
  40. * extras: mirrors.aliyun.com
  41. * updates: mirrors.aliyun.com
  42. repo id repo name status
  43. base//x86_64 CentOS- - Base - mirrors.aliyun.com ,
  44. extras//x86_64 CentOS- - Extras - mirrors.aliyun.com
  45. updates//x86_64 CentOS- - Updates - mirrors.aliyun.com ,
  46. repolist: ,
  47. #--------------------------------------------------------------------------

更新系统(可选)

  1. yum update

删除docker旧版本

  1. # 有旧版本的docker话,可以用下面命令删除
  2. yum remove docker docker-common docker-selinux docker-engine

安装 Docker CE

  1. yum install -y yum-utils device-mapper-persistent-data lvm2
  2. # yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  3. yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  4. yum install -y docker-ce
  5. #--------------------------------------------------------------------------
  6. .......
  7. Installed:
  8. docker-ce.x86_64 :17.09..ce-.el7.centos
  9.  
  10. Dependency Installed:
  11. audit-libs-python.x86_64 :2.7.-.el7
  12. checkpolicy.x86_64 :2.5-.el7
  13. container-selinux.noarch :2.28-.git85ce147.el7
  14. libcgroup.x86_64 :0.41-.el7
  15. libseccomp.x86_64 :2.3.-.el7
  16. libsemanage-python.x86_64 :2.5-.el7
  17. policycoreutils-python.x86_64 :2.5-17.1.el7
  18. python-IPy.noarch :0.75-.el7
  19. setools-libs.x86_64 :3.3.-1.1.el7
  20. ......
  21. #--------------------------------------------------------------------------

若需要安装指定的版本时,可参照以下命令

  1. # 根据需要选择是否开启edge和test repositories
  2. yum-config-manager --enable docker-ce-edge
  3. yum-config-manager --enable docker-ce-test
  4. ## 禁用命令
  5. yum-config-manager --disable docker-ce-edge
  6.  
  7. ## 安装指定的版本
  8. yum list docker-ce --showduplicates | sort -r
  9. #--------------------------------------------------------------------------
  10. Loading mirror speeds from cached hostfile
  11. Loaded plugins: fastestmirror
  12. Installed Packages
  13. docker-ce.x86_64 17.09..ce-.el7.centos docker-ce-stable
  14. docker-ce.x86_64 17.09..ce-.el7.centos @docker-ce-stable
  15. docker-ce.x86_64 17.09..ce-.el7.centos docker-ce-stable
  16. docker-ce.x86_64 17.06..ce-.el7.centos docker-ce-stable
  17. docker-ce.x86_64 17.06..ce-.el7.centos docker-ce-stable
  18. docker-ce.x86_64 17.06..ce-.el7.centos docker-ce-stable
  19. docker-ce.x86_64 17.03..ce-.el7.centos docker-ce-stable
  20. docker-ce.x86_64 17.03..ce-.el7.centos docker-ce-stable
  21. docker-ce.x86_64 17.03..ce-.el7.centos docker-ce-stable
  22. Available Packages
  23. #--------------------------------------------------------------------------
  24.  
  25. yum install docker-ce-17.06..ce

启动docker

  1. systemctl start docker
  2.  
  3. # 查看docker的版本信息
  4. docker version
  5. #--------------------------------------------------------------------------
  6. Client:
  7. Version: 17.09.-ce # 客户端版本
  8. API version: 1.32
  9. Go version: go1.8.3
  10. Git commit: 19e2cf6
  11. Built: Thu Dec ::
  12. OS/Arch: linux/amd64
  13.  
  14. Server:
  15. Version: 17.09.-ce # 服务端版本
  16. API version: 1.32 (minimum version 1.12)
  17. Go version: go1.8.3
  18. Git commit: 19e2cf6
  19. Built: Thu Dec ::
  20. OS/Arch: linux/amd64
  21. Experimental: false
  22. #--------------------------------------------------------------------------
  23.  
  24. # 查看网络信息
  25. ip addr
  26. #--------------------------------------------------------------------------
  27. : lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN qlen
  28. link/loopback ::::: brd :::::
  29. inet 127.0.0.1/ scope host lo
  30. valid_lft forever preferred_lft forever
  31. inet6 ::/ scope host
  32. valid_lft forever preferred_lft forever
  33. : ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc mq state UP qlen
  34. link/ether :::ab:4c: brd ff:ff:ff:ff:ff:ff
  35. inet 10.240.4.185/ brd 10.240.4.255 scope global ens160
  36. valid_lft forever preferred_lft forever
  37. inet6 fe80:::56ff:feab:4c50/ scope link
  38. valid_lft forever preferred_lft forever
  39. : docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu qdisc noqueue state DOWN # docker0 虚拟网桥
  40. link/ether :::ac::bf brd ff:ff:ff:ff:ff:ff
  41. inet 172.17.0.1/ scope global docker0
  42. valid_lft forever preferred_lft forever
  43. inet6 fe80:::72ff:feac:5bf/ scope link
  44. valid_lft forever preferred_lft forever
  45. #--------------------------------------------------------------------------
  46.  
  47. systemctl list-unit-files | grep docker
  48. #--------------------------------------------------------------------------
  49. docker.service disabled
  50. #--------------------------------------------------------------------------
  51.  
  52. # 设置成自启服务
  53. systemctl enable docker.service
  54.  
  55. # 查看状态
  56. systemctl status docker
  57. #--------------------------------------------------------------------------
  58. docker.service - Docker Application Container Engine
  59. Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
  60. Active: active (running) since Tue -- :: CST; 13min ago
  61. Docs: https://docs.docker.com
  62. Main PID: (dockerd)
  63. CGroup: /system.slice/docker.service
  64. ├─ /usr/bin/dockerd
  65. └─ docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libco...
  66.  
  67. Dec :: docker01 dockerd[]: time="2017-12-12T17:24:29.594209004+08:00" level=info msg="libcontainerd: new containerd process, pid: 23490"
  68. Dec :: docker01 dockerd[]: time="2017-12-12T17:24:30.596093094+08:00" level=warning msg="failed to rename /var/lib/docker/tmp for background deletio...chronously"
  69. Dec :: docker01 dockerd[]: time="2017-12-12T17:24:30.654014669+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
  70. Dec :: docker01 dockerd[]: time="2017-12-12T17:24:30.654714697+08:00" level=info msg="Loading containers: start."
  71. Dec :: docker01 dockerd[]: time="2017-12-12T17:24:30.852920366+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17...IP address"
  72. Dec :: docker01 dockerd[]: time="2017-12-12T17:24:30.996504508+08:00" level=info msg="Loading containers: done."
  73. Dec :: docker01 dockerd[]: time="2017-12-12T17:24:31.004149257+08:00" level=info msg="Docker daemon" commit=19e2cf6 graphdriver(s)=overlay version=17.09.-ce
  74. Dec :: docker01 dockerd[]: time="2017-12-12T17:24:31.004282017+08:00" level=info msg="Daemon has completed initialization"
  75. Dec :: docker01 dockerd[]: time="2017-12-12T17:24:31.015479108+08:00" level=info msg="API listen on /var/run/docker.sock"
  76. Dec :: docker01 systemd[]: Started Docker Application Container Engine.
  77. Hint: Some lines were ellipsized, use -l to show in full.
  78. #--------------------------------------------------------------------------

运行hello-world image验证docker安装是否成功

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

升级和卸载docker

  1. # 升级
  2. yum -y upgrade docker-ce
  3.  
  4. # 卸载
  5. yum remove docker-ce
  6.  
  7. # 删除Images, containers, volumes, or customized configuration files
  8. rm -rf /var/lib/docker

使用阿里镜像加速器

使用阿里云专属加速器加快获取Docker官方镜像,否则在国内速度会慢到你无法忍受哒。步骤如下:

  1. 免费注册一个阿里云账号 www.aliyun.com
  2. 进入加速器页面 https://cr.console.aliyun.com/#/accelerator
  3. 选择镜像加速器

按图中进行相关配置

  1. # 下面的xxxxx要替换成你的专属加速器的地址哦
  2. tee /etc/docker/daemon.json <<-'EOF'
  3. {
  4. "registry-mirrors": ["https://xxxxxxx.mirror.aliyuncs.com"]
  5. }
  6. EOF
  7.  
  8. systemctl daemon-reload
  9. systemctl restart docker

Docker的部署安装(CentOS)的更多相关文章

  1. Docker的部署安装(CentOS)-by paymob

    环境准备 通过命令查看系统版本和内核版本等信息 [gmuser@--- ~]$ cat /etc/redhat-release CentOS Linux release (Core) [gmuser@ ...

  2. Devops实战(一)Docker的部署安装以及Docker-Compose的使用

    Docker的部署安装以及Docker-Compose的使用 1.docker和docker-Compose简介 Docker是一组平台即服务(PaaS)产品,它们使用操作系统级虚拟化以称为容器的软件 ...

  3. docker运行环境安装-centos(一)

    在这里我们使用的是docker的社区版Docker CE,针对的是未安装docker的新的主机,如果安装过docker的早期版本,先卸载它们及关联的依赖资源,安装的版本为docker 18.03. 1 ...

  4. (二)docker的部署安装,配置,基础命令

    一.docker 的安装部署 这里不过多介绍,下面这两个linux发型版 安装可以参考 ubuntu的 docker-ce安装 centos7的 docker-ce安装 二.docker配置文件 重要 ...

  5. docker之windows安装&centOS安装

    按这个安装  没什么毛病 https://blog.csdn.net/vitaair/article/details/80894890 https://www.runoob.com/docker/ce ...

  6. 【Docker学习之二】Docker部署安装

    环境 docker-ce-19.03.1-3.el7.x86_64 一.Docker的部署安装 Docker采用Linux(内核)技术,所以只能运行在Linux上,官方说Linux kernel至少3 ...

  7. Docker学习笔记_04 Rancher的部署安装(编排选用K8S)

    原文地址:http://dbase.cc/2018/01/12/docker/04_rancher的部署安装/ 为什么要使用Rancher Rancher是一个开源的企业级容器管理平台.通过Ranch ...

  8. Rancher的部署安装(编排选用K8S)

    为什么要使用Rancher Rancher是一个开源的企业级容器管理平台.通过Rancher,企业再也不必自己使用一系列的开源软件去从头搭建容器服务平台.Rancher提供了在生产环境中使用的管理Do ...

  9. 【docker部署】基于linux的centos操作系统部署安装docker容器

    一.docker介绍 容器是轻量级的,包含应用运行所需所有东西(代码.库.运行时环境.系统设置,以及依赖关系)的独立的包.每个容器都部署于它自己的 CPU.内存.块 I/O,以及网络资源上,所有这些都 ...

随机推荐

  1. AES学习小结

    AES是基于数据块的加密方式,即每次处理的数据是一块(16字节),当数据不是16字节的倍数时填充,这就是所谓的分组密码(区别于基于比特位的流密码),16字节是分组长度. AES支持五种模式:CBC,C ...

  2. web项目servlet&jsp包失效问题

    今天偶然遇到这样的一个问题,故做个总结. javaee开发只用到serlet和jsp两个包.而sun提供的jdk只是javase部分的包,对于se部分只提供了规范,而包由容器给出. 由于自己在新建好一 ...

  3. 阿里云服务器下安装配置phpMyAdmin

    1.下载phpMyAdmin wget http://www.phpmyadmin.net/home_page/downloads.php 2.解压下载的文件 tar -zvxf phpMyAdmin ...

  4. TensorFlow中的Session、Graph、operation、tensor

    TensorFlow中的Session.Graph.operation.tensor

  5. Java之同步方法处理继承Thread类的线程安全问题

    /** * 使用同步方法处理继承Thread类的方式中的线程安全问题 * */class Window4 extends Thread { private static int ticket = 10 ...

  6. python-day4爬虫基础之正则表达式

    正则表达式:(字符串匹配) 使用单个字符串来描述匹配一系列符合某个句法规则的字符串 是对字符串操作的一种逻辑公式 应用场景:处理文本和数据 正则表达式过程:依次拿出表达式和文本中的字符比较,如果每一个 ...

  7. IntelliJ IDEA2018.2.7安装和破解教程

    一.安装 IntelliJ IDEA2018.2.7 IDEA官网下载地址链接:https://www.jetbrains.com/idea/download/previous.html 1.进入网站 ...

  8. Windows Boot Manager、Bootmgfw.efi、Bootx64.efi、bcdboot.exe 文件的关系

    本教程针对于UEFI启动来叙述的,根据普遍的支持UEFI的机器来叙述. 标题简要说明:Windows Boot Manager  --------安装完Windows系统后而出现的启动选项(相关的信息 ...

  9. [前端] VUE基础 (5) (过滤器、生命周期、钩子函数)

    一.过滤器 过滤器分为局部过滤器和全局过滤器. 1.局部过滤器 <body> <div id="app"> </div> <script ...

  10. typescript-学习使用ts-3

    函数 函数参数 参数及返回值类型 function add(x: number, y: number): number { return x + y } 可选参数 function add(x: nu ...