Centos7中安装docker
2016-04-21 14:10
716 查看
CentOS
Docker 可以运行在CentOS 7系列,也可以安装在其他二进制兼容 EL7发行版的系统中,比如 科学Linux(Scientific Linux)可以成功安装,但是Docker没有做测试或者支持 Docker 在这些发行版上安装。这一节会指导你去安装使用 Docker-managed 发布包和安装机制。确保使用的这些包是Docker
最新版的。如果你想要使用 CentOS-managed 包,请查询 CentOS 的文档
前提
Docker要求64位的系统,对CentOS版本不做要求,并且你的内核必须是3.10及以上。检查你当前内核的版本,可以在终端中使用
uname -r去显示你的内核版本:
$ uname -r
3.10.0-229.el7.x86_64
最后,推荐完全更新你的系统,请牢记被打补丁来修复了任何潜在的内核 bugs。任何被上报的内核 bugs 应该已经完全使用最新的内核软件包被修复了。
安装
有两种方法安装 Docker Engine:第一种:可以使用
yum管理器安装,或者使用
curl
get.docker.com;
第二种:运行一个通过
yum包管理的安装脚本安装;
Install with yum
登陆你的机器使用 sudoor
root特权.
确保你的yum包是最新的:
$ sudo yum update
添加yum repo.
$ 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
安装 Docker package.
$ sudo yum install docker-engine
启动Docker daemon.
$ sudo service docker start
通过在容器中运行一个测试镜像确保docker安装成功。
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from hello-world
a8219747be10: Pull complete
91c95931e552: Already exists
hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:aa03e5d0d5553b4c3473e89c8619cf79df368babd1.7.1cf5daeb82aab55838d
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.
(Assuming it was not already locally available.)
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 itto your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
For more examples and ideas, visit:
http://docs.docker.com/userguide/[/code]登陆你的机器使用sudo或者root特权
使用脚本安装
确保你的yum是最新的$ sudo yum update
运行Docker安装脚本$ curl -sSL https://get.docker.com/ | sh
这个脚本添加docker.repo仓库,然后安装Docker
启动Docker daemon$ sudo service docker start
通过在容器中运行一个测试镜像确保docker安装成功$ sudo docker run hello-world
Docker daemon绑定了一个Unix socket而不是TCP端口。默认root用户拥有Unix socket,其他用户可以通过sudo来访问它。出于这个原因,docker daemon总是以root用户身份运行。
创建一个docker组
当你用docker命令时,为了避免使用sudo命令,我们可以创建一个叫做 docker 的组 ,并且将用户添加进去。当再次启动docker daemon时,使得Unix socket 读写的所有权以docker组的身份运行。
Warning: 在进行docker操作时,这个docker 组和root用户是等价的;关于如何影响系统安全想要获取更多详细信息,可以参照Docker
Daemon Attack Surface。
接下来创建docker组并添加用户user:
登陆系统Centos。
创建docker组并添加用户$sudo usermod -aG docker your_username
注销系统然后重新登录系统,确保你的用户正在运行并且有正确的权限
通过使用不加sudo的docker命令运行一个容器来验证以上几步的正确性:$ docker run hello-world为了确保Docker在系统启动时运行,可以这样做:
设置docker daemon开机启动[code]$ sudo systemctl enable docker[/code]你可以使用yum命令卸载Docker
卸载
列出已经安装的软件包。$ yum list installed | grep dockeryum list installed | grep dockerdocker-engine.x86_64 1.7.1-1.el7 @/docker-engine-1.7.1-1.el7.x86_64.rpm
删除软件包.
$ sudo yum -y remove docker-engine.x86_64
这个命令不会删除主机上的镜像、容器、卷、用户创建的配置文件
删除所有镜像、容器和卷,可以使用如下命令:$ rm -rf /var/lib/docker
查找删除用户创建的任何docker文件。.
相关文章推荐
- Docker: 虚拟机与宿主机端口映射(Mac)
- Docker Swarm入门教程
- Jenkins+Github+Docker+Maven实现持续集成
- 试用 Nexus OSS 3.0 的docker仓库 (二)
- <VR + Docker> 系列文章和視頻
- VR+Docker: 3D动漫的应用范例及其效益
- VR+Docker: 3D动漫<DOCKER化>的应用范例及其效益
- VR內容素材的標準化<打包>方法
- docker笔记
- centos 6.6 x86_64 安装docker和简单使用
- docker 容器间的连接
- Docker run执行流详解(以volume,network和libcontainer为线索)
- Docker配置指南系列(一):配置项管理
- Docker 4 -- 总结
- docker入门——简单操作
- 试用 Nexus OSS 3.0 的docker仓库 (一)
- 两种方式创建你自己的 Docker 基本映像
- Windows8下安装Docker
- Docker玩转Rhadoop
- Docker 学习笔记