您的位置:首页 > 运维架构 > Docker

Centos下安装Docker容器

2018-03-23 15:00 393 查看
首先声明本文旨在介绍centos环境下安装Docker-CE(社区版),社区版是免费提供给个人开发者和小团队,Docker-EE (企业版)有额外费用,想了解其他系统下搭建,请传送《docker官网》

准备工作

1、docker要求Linux内核大于等于3.10,所以在安装之前我们使用命令 uname -r 检测系统是否支持

[root@localhost ~]# uname -r
3.10.0-693.21.1.el7.x86_64

2、更新 yum包,按提示操作即可

[root@localhost ~]# yum update


卸载旧版本的docker

如果第一次安装,跳过此步骤

[root@localhost ~]# yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine


安装Docker CE

官方推荐使用docker repository安装

创建仓库

1、安装 yum-utils,还有两个驱动依赖,device-mapper-persistent-data 和 lvm2

[root@localhost ~]# yum install -y yum-utils \
device-mapper-persistent-data \
lvm2


2、使用以下命令设置yum仓库

[root@localhost ~]# yum-config-manager \
--add-repo \ https://download.docker.com/linux/centos/docker-ce.repo[/code] 

下载Docker CE

1、查看docker历史版本

[root@localhost docker]# yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror, langpacks
可安装的软件包
* updates: ftp.sjtu.edu.cn
Loading mirror speeds from cached hostfile
* extras: centos.ustc.edu.cn
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
* base: centos.ustc.edu.cn


2、下载最新稳定版

[root@localhost docker]# yum install docker-ce.x86_64
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: ftp.sjtu.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker-ce.x86_64.0.18.03.0.ce-1.el7.centos 将被 安装
--> 正在处理依赖关系 container-selinux >= 2.9,它被软件包 docker-ce-18.03.0.ce-1.el7.centos.x86_64 需要
--> 正在处理依赖关系 pigz,它被软件包 docker-ce-18.03.0.ce-1.el7.centos.x86_64 需要
--> 正在检查事务
---> 软件包 container-selinux.noarch.2.2.42-1.gitad8f0f7.el7 将被 安装
---> 软件包 pigz.x86_64.0.2.3.3-1.el7.centos 将被 安装
--> 解决依赖关系完成
.
.
.
.省略N多行
.....
完毕!


3、 使用命令 docker -v 查看安装Docker版本

[root@localhost docker]# docker -v
Docker version 18.03.0-ce, build 0520e24


4、设置开机启动docker

[root@localhost docker]# systemctl start docker


5、运行hello-world 校验,看到如下日志说明安装完毕

[root@localhost docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
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:
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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Docker