CentOS下安装Docker
简介:本篇文章介绍如何在CentOS系统下面安装docker系统。
官方文档:https://docs.docker.com/install/linux/docker-ce/centos/
Docker支持以下的CentOS版本:
- CentOS 7 (64-bit)
- CentOS 6.5 (64-bit) 或更高的版本
从 2017 年 3 月开始 docker 在原来的基础上分为两个分支版本: Docker CE 和 Docker EE。
Docker CE 即社区免费版,Docker EE 即企业版,强调安全,但需付费使用。
本文介绍 Docker CE 的安装使用。
一、前提条件
目前,CentOS 仅发行版本中的内核支持 Docker。
Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。
Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本。
1.1 依赖性检查
Docker需要一个64位系统的Linux系统,内核的版本必须大于3.10。可以用下面的命令来检查是否满足docker的要求。
通过如下命令查看你当前的内核版本:
$ sudo uname -r
3.10.-.el7.x86_64
如果上述的依赖满足的话,还是推荐您全面地更新Linux系统,以保证内核相应的bug都得到修复。
通过如下命令来更新Linux系统:
$ sudo yum update
1.2 卸载旧版本
较旧版本的Dokcer被称为docker或docker-engine。如果已经安装这些,请卸载它们以及相关的依赖项。
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
二、安装
目前CentOS系统下面安装docker可以有三种方式:
- 使用curl获得docker的安装脚本进行安装:
- 通过sh脚本安装
- 下载rpm包安装
- 使用yum包管理器来安装docker,推荐使用此方式进行安装
2.1 使用sh安装脚本安装
1.使用一个有sudo权限的账号登录CentOS系统。
2.更新现有的yum包。
$ sudo yum update
3.执行docker安装脚本。
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
这个脚本会添加docker.repo源并安装Docker。
如果出现
+sh -c 'yum install -y -q docker-ce'
那么执行:
yum install -y -q docker-ce
如果出现
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
那么执行
yum provides '*/applydeltarpm'
yum install deltarpm
4.启动docker服务。
$ sudo systemctl start docker
5.确认docker安装成功
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
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:
. The Docker client contacted the Docker daemon.
. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
. 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/
2.2 下载rpm包安装
1.转到https://download.docker.com/linux/centos/7/x86_64/stable/Packages/并下载.rpm要安装的Docker版本的文件。
$ sudo wget -P /tmp/ https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.09.3-3.el7.x86_64.rpm
-P 指定下载到/tmp/目录下
2.安装Docker CE。
$ sudo yum install /tmp/docker-ce-18.09.-.el7.x86_64.rpm
3.启动Docker
$ sudo systemctl start docker
4.确认docker是否安装成功
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
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:
. The Docker client contacted the Docker daemon.
. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
. 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/
5.升级Docker CE
要升级Docker CE,请下载较新的软件包文件并重复以上的安装过程,但要注意的是,要使用yum -y upgrade 而不是使用yum -y install 并指向新文件。
2.3 使用yum包安装
1.使用有sudo权限的账号登录系统。
2.更新yum包。
$ sudo yum update
3.安装一些所需的包
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
4.添加docker源,并更新yum缓存
$ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新yum缓存
$ sudo yum makecache fast
这个脚本会添加docker.repo源并安装Docker
5.安装Docker
$ sudo yum -y install docker-ce
6.启动docker服务
$ sudo systemctl start docker
7.确认docker是否安装成功
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
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:
. The Docker client contacted the Docker daemon.
. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
. 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
可以使用yum来删除docker。
1.列出docker包的具体的名字
$ sudo yum list installed | grep docker
containerd.io.x86_64 1.2.4-3.1.el7
docker-ce.x86_64 :18.09.-.el7
docker-ce-cli.x86_64 :18.09.-.el7
2.删除docker
$ sudo yum -y remove containerd.io.x86_64 \
docker-ce.x86_64 \
docker-ce-cli.x86_64
备注:该命令只会删除docker运行环境,并不会删除镜像,容器,卷文件,以及用户创建的配置文件。
3.清楚镜像和容器文件
$ sudo rm -rf /var/lib/docker
4.手动查找并删除用户创建的配置文件。
四、Docker安装的可选配置
4.1 以非root用户管理Docker
Docker守护程序绑定到Unix socket而不是TCP端口。默认情况下,Unix socke是root用户才有,而其他用户只能通过使用sudo使用它。Docker守护程序始终以root用户身份运行。
如果您不想在docker命令前加上sudo
,请创建一个名为docker的Unix组
并向其添加用户。当Docker守护程序启动时,它会创建一个可由该docker
组成员访问的Unix socket。
1.创建docker组
$ sudo groupadd docker
2.添加user到docker组
$ sudo usermod -aG docker $USER
请将$USER替换为系统中你的除root外的某个用户。
3.注销并重新登录,以便重新评估您的组成员身份。
如果在虚拟机上进行测试,则可能需要重新启动虚拟机才能使更改生效。
4.验证是否可以通过不使用sudo运行docker命令。
$ docker run hello-world
如果最初在添加用户到docker组之前,使用的是sudo的Dokcer CLI命令。你可能会出现如下错误,表明你的~/.docker目录由于sudo命令而创建的权限不正确。
WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied
要解决此问题,请删除~/.docker/目录(它会自动重新创建,但任何自定义设置都会丢失),或使用以下命令更改其所有权和权限:
$ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
$ sudo chmod g+rwx "$HOME/.docker" -R
4.2 配置在系统启动时启动Docker
$ sudo systemctl enable docker
如果要禁用此行为,请改用disable。
$ sudo systemctl disable docker
4.3 镜像加速
鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,我们可以需要配置加速器来解决。
Docker国内镜像:
- 网易加速器:http://hub-mirror.c.163.com
- 官方中国加速器:https://registry.docker-cn.com
- ustc的镜像:https://docker.mirrors.ustc.edu.cn
也可使用私人镜像加速器地址,如使用阿里云的镜像加速器:登录阿里云->产品->搜索"容器镜像服务"->镜像库->镜像加速器。
新版的 Docker 使用 /etc/docker/daemon.json(Linux) 来配置 Daemon。
请在该配置文件中加入(没有该文件的话,请先建一个):
$ sudo cd /etc/docker/
$ sudo vi daemon.json
{
"registry-mirrors": ["https://hub-mirror.c.163.com"]
}
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
CentOS下安装Docker的更多相关文章
- docker学习之路-centos下安装docker
前言 我要在云服务器上做一个asp.net core的webapi应用,使用docker来部署应用,中间用到的任何组件包括nginx和sqlserver 2017都是用docker来装载运行,所以,这 ...
- Centos下安装Docker,并配置国内docker源
Centos下安装Docker 替换为国内的yum源(可选): mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.re ...
- 在RedHat/CentOS下安装Docker(不升级内核)
由于内核版本问题,最初仅Ubuntu可以较好的支持Docker.不过,由于RedHat系列OS(REHL.CentOS)是目前主流的Linux服务器操作系统,所以令RedHat系列OS支持Docker ...
- Linux 64位 CentOS下安装 Docker 容器,启动、停止
一.Docker简介 Docker 提供了一个可以运行你的应用程序的封套(envelope),或者说容器,是轻量级的“容器引擎+映像仓库”,在LXC(linux轻量级容器)的基础上构建,可以运行任何应 ...
- CentOS下安装Docker CE教程
一.安装前准备 1.硬件要求 CentOS 7(64-bit),内核版本不能低于3.10: CentOS 6.5(64-bit或更新的版本),内核版本为 2.6.32-431 或者更高版本,一般不建议 ...
- 1. centos下安装docker
CentOS Docker 安装 Docker支持以下的CentOS版本: CentOS 7 (64-bit) CentOS 6.5 (64-bit) 或更高的版本 前提条件 目前,CentOS 仅发 ...
- centos下安装docker最新版教程
1.通过yum安装需要root或者能sudo的权限 yum包更新到最新$ sudo yum update 添加Docker yum源$ sudo tee /etc/yum.repos.d/docker ...
- Linux(CentOS)下安装docker
Linux(CentOS)安装Docker 查看当前内核版本 [docker@localhost ~]$ uname -r 确保yum包更新到最新 [docker@localhost ~]$ sudo ...
- Centos下安装Docker集群管理工具Shipyard
一. Docker Shipyard是什么 ? shipyard是一个开源的docker管理平台,其特性主要包括: 支持镜像管理.容器管理. 支持控制台命令 容器资源消耗监控 支持集群swarm,可以 ...
随机推荐
- JS 语法大全
来源http://blog.csdn.net/newegg2009/article/details/6230582 js语法2008年03月19日 星期三 11:14一.js的数据类型和变量 Java ...
- 切线空间(Tangent Space)
http://download.autodesk.com/global/docs/maya2012/zh-cn/index.html?url=files/Polygons_nodes_Tangent_ ...
- springboot 配置jsp支持
springboot默认并不支持jsp模板,所以需要配置. 下面是一个可以运行的例子: 首先配置属性文件: spring.http.encoding.force=true spring.http. ...
- Golang之继承,多重继承(struct)
热乎的代码来了 package main import "fmt" /* 继承 一个结构体嵌到另一个结构体,称作组合 匿名和组合的区别 如果一个struct嵌套了另一个匿名结构体, ...
- Sketch插件新利器——使用Mockplus DS制作设计规范
Sketch,作为一款专为图标和界面设计而打造的优质矢量绘图工具,也是设计师们制作和完善公司企业内部设计规范系统不可或缺的设计工具. 然而,逐个导出和上传Sketch编辑优化的设计系统资源费时而费力. ...
- 购买阿里云的云服务器时选择镜像centos时应该选择哪个版本
购买阿里云的云服务器时选择镜像centos时应该选择哪个版本 方法/步骤首先,我们要清楚的便是每个系统之间的差别,以及在阿里云上的差别:1. Windows1.1) 系统内含正版激活.1.2) 适合于 ...
- 何时使用[self release]
这样的语句 [self release]; 乍看上去让人很困惑. 从release方法本身的作用上来说,就是给self的引用技术减一,就像release对其他对象所做的一样. 一般来说,唯一用到, ...
- 声音处理(Cool Edit)
平直化处理 上升半音
- Android-有序广播是可以中断的
在之前的博客,Android-广播概念,中介绍了(广播和广播接收者)可以组件与组件之间进行通讯,有两种类型的广播(无序广播 和 有序广播),这篇博客就来讲解有序广播的代码实现: 有序广播:接收者 可以 ...
- github的使用经历
首先我打开百度搜索markdown,点击这个在线编辑器,开始编写,如下图: 预览效果如下: 然后打开github的网页登录后,点击下图这个标志: 然后给给要上传的一个命名: 然后选择README 确认 ...