centos7安装docker总结

最近工作中需要用到docker,所以决定自己搭建一个docker环境,于是选择在virtualbox上安装centos7虚拟机,并在虚拟机上安装docker,没搭建环境之前,觉得应该很简单,没想到折腾了好长时间。比如安装的centos7版本不支持docker,最后导致重装,所以特此记录下安装步骤及注意事项。

1) 创建虚拟机,选择centos系统镜像,比如CentOS-7-x86_64-DVD-1708.iso,务必使用官方最新支持的版本,如果选择的镜像版本不对,会导致安装完docker无法运行;

2)开始安装虚拟机,如果需要图形化界面,在安装最后一步记得选择带图形安装;

3)安装完毕,重启后,需要同意许可才能进入系统,如果是命令行界面,记得仔细阅读提示信息,需输入相应的选项同意许可才能进入系统;

4)安装virtualbox增强功能,一般会提示缺少gcc、make、perl和其他库文件,需安装和系统内核版本一致的库文件,否则不能安装virtualbox增强功能,例如:

Verifying archive integrity... All good.
Uncompressing VirtualBox 5.2.6 Guest Additions for Linux........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.
This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-693.el7.x86_64
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.
This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-693.el7.x86_64
Press Return to close this window...

按照提示信息,安装所需的工具和库:

# yum install gcc make perl
# yum install kernel-devel-$(uname -r)
# rpm -qa kernel\*
kernel-3.10.0-693.el7.x86_64
kernel-tools-3.10.0-693.el7.x86_64
kernel-headers-3.10.0-693.el7.x86_64
kernel-devel-3.10.0-693.el7.x86_64
kernel-tools-libs-3.10.0-693.el7.x86_64

再次安装virtualbox增强功能,成功安装。

5)安装docker:

$ curl -fsSL https://get.docker.com/ | sh
$ systemctl start docker
$ systemctl status docker
$ systemctl enable docker

安装docker,并启动docker,然后将docker服务设置成开机自启动。

6)运行docker hello world示例:

$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7
Status: Downloaded newer image for hello-world:latest
$ 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://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

至此,成功在centos7上安装docker。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 最近研究了几天docker的快速部署,感觉很有新意,非常轻量级和方便,打算在公司推广一下,解放运维,省得每次部署一...
    Helen_Cat阅读 5,206评论 0 4
  • Docker — 云时代的程序分发方式 要说最近一年云计算业界有什么大事件?Google Compute Engi...
    ahohoho阅读 15,707评论 15 147
  • 0x01 核心概念 Docker镜像类似于虚拟机镜像,可以理解为一个面向Docker引擎的只读模板,包含了文件系统...
    闲云逸心阅读 10,231评论 0 9
  • 以下原文转载于(https://docs.docker.com/docker-for-mac/)(想找中文版的最新...
    Veekend阅读 12,238评论 0 17
  • 很少写字这么快的,很多时候感觉写快一点就会潦草,以前上学的时候语文老师就是一笔一画教的,小学和初中的语文老师写字都...
    文武东西阅读 3,698评论 1 4