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,可以 ...
随机推荐
- Linux --centos7 开机启动设置
以Linux下指定sun用户在linux开机时执行/home/sun/startrun.sh为例: 以root登录linux 执行vi /etc/rc.d/rc.local 在文档末尾添加一行语句:s ...
- loadrunner--web_url函数用法
web_url语法: Int Web_url(const char *name, const char * url, <Lists of Attributes>, [EXTR ...
- 洛谷 P2899 [USACO08JAN]手机网络Cell Phone Network(树形动规)
题目描述 Farmer John has decided to give each of his cows a cell phone in hopes to encourage their socia ...
- git 查询某人的提交记录
git log --author=liubo --name-only
- GCT英语口语复试中的常见问题总汇
英语口语复试中常见的问题: 1. Where do you come from? 2. What kind of landscape surrounds your hometown? 3. What ...
- Zookeeper客户端cli_st为何在crontab中运行不正常?
实践中,发现直接在命令行终端运行cli_st时,能够得到预期的结果,但一将它放到crontab中,则只收到: bye 相关的一段clit_st源代码如下: if (FD_ISSET(, &rf ...
- .NET基础 (19)多线程
多线程编程的基本概念1 请解释操作系统层面上的线程和进程2 多线程程序在操作系统里是并行执行的吗3 什么是纤程 .NET中的多线程1 如何在.NET程序中手动控制多个线程2 如何使用.NET的线程池3 ...
- polymer入门例子-已过时
这个教程挺不错!:http://blog.csdn.net/renfufei/article/details/37040883 过时了,现在的版本已经为1.0了 一:创建APP结构 本教程会使用预先构 ...
- [翻译]Event Handler Description 事件处理描述
Event Handler Description 事件处理描述 (自定义控件) How should a new event handler be defined if it does not ...
- 代码修改之后MSbuild编译不出最新的dll解决方法
问题: 使用jenkins发布的时候,开发不断反馈自己修改的文件使用jenkins没有发布到测试环境.经过查证发现使用MSBUILD编译的时出现修改的文件编译出的日期不是最新日期,但是使用VS编译就不 ...