Docker 在 CentOS 下的安装、使用

Stella981
• 阅读 636

原文同步至 http://waylau.com/docker-installation-centos/

本文介绍了 Docker 在 CentOS 环境下的详细安装过程,并尝试运行一个最简单的 image 来感受下 Docker 的风采。

什么是 Docker

Docker 在 CentOS 下的安装、使用

Docker 是为开发人员和系统管理员用于构建、发布、并运行分布式应用程序的开放式平台。该平台由 Docker 引擎(一个便携、轻巧的运行时和打包工具) 和 Docker Hub (一个共享应用程序和自动化工作流的云服务)等组成。Docker 可以使应用程序从组件迅速组装并消除了开发、质量保证和生产环境之间的摩擦问题。这样一来,IT部门可以更快地发布,而这些应用程序不管是运行在笔记本电脑、数据中心的虚拟机,还是任何的云,其运行过程和结果都是一致的。

更多有关 Docker 的介绍,可以参阅《简述 Docker》 一文。

前置条件

使用 uname -r 检查 kernel 版本

$ uname -r
3.10.0-327.el7.x86_64

建议你使用最新的系统,以为一直的 bug 都会在新的 kernel 发布中修复。

安装

yum 方式安装

1.使用 sudo 或 root 权限的用户登入系统。

2.确保你的 yum 是最新的

sudo yum update

3.添加 yum 仓库

$ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

注意,只能用[Ctrl]d结束,而不能用[Ctrl]c

4.安装 Docker 包

$ sudo yum install docker-engine

出现下面错误

Loaded plugins: fastestmirror

就是 fastestmirror 插件错误,可以禁用该插件也可以暂时不理会,这并不影响 docker-engine 的安装。

禁用该 fastestmirror 插件

vi /etc/yum/pluginconf.d/fastestmirror.conf
enabled=1改成0

启动 docker 守护进程

$ sudo  systemctl start docker.service

配置让 docker 服务随系统自动启动

$ sudo chkconfig docker on

验证 docker 是否安装成功

$ sudo systemctl enable docker.service

如果出错:

[waylau@waylau ~]$ sudo docker run hello-world
[sudo] password for waylau:
Sorry, try again.
[sudo] password for waylau:
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fhello-world%3Apull&service=registry.docker.io: dial tcp: lookup auth.docker.io on 8.8.8.8:53: no such host.

添加当前用户waylau到 docker 用户组

$ sudo usermod -aG docker waylau

并重复多几次(最好能翻墙,毕竟服务器在国外)最后成功的界面如下:

[waylau@waylau ~]$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
Pulling repository docker.io/library/hello-world
975b84d108f1: Pull complete
3f12c794407e: Pull complete
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world: this image was pulled from a legacy registry.  Important: This registry version will not be supported in future versions of docker.

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.
 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 Hub account:
 https://hub.docker.com

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

整个过程是这样的:

  1. Docker 客户端连接到 Docker 守护进程;
  2. Docker 守护进程从 Docker Hub 中拉取名为 "hello-world" 的 image(镜像);
  3. Docker 守护程序从该 image 中创建新的容器,该容器执行输出动作,输出的内容就是上面所看到的;
  4. Docker 守护程序将输出流到 Docker 客户端并发送你的终端显示。

查看 docker image

可以看到 pull 回来的这个 image 的一个情况,大小不到 1k。

[waylau@waylau ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              690ed74de00f        4 months ago        960 B

参考

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
11个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
4年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Stella981 Stella981
3年前
KVM调整cpu和内存
一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
1年前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
美凌格栋栋酱 美凌格栋栋酱
5个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(