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

1.1.1.3、CentOS

2015-11-17 23:39 731 查看


CentOS

Docker 运行在CentOS 7.X上。 Docker可以在一个兼容EL7系统(如:Scientific Linux)上安装成功,但是,Docker 对这些发行版不提供任何的测试和支持。

这个章节会指导你使用Docker-managed发布包和安装机制去安装。使用这个包确保你获得Docker的最新发行版。如果你希望使用CentOS-managed 包,请查阅Centos的相关文档。


先决条件

Docker 的安装,需要一个不管任何版本的64位CentOS系统。并且,你的内核必须要3.10以上,例如,CentOS 7。

检查你当前系统的内核版本,打开一个终端并执行
uname -r
命令去显示你的内核版本:
$ uname -r
3.10.0-229.el7.x86_64


最后,建议你全面升级你的系统。务必牢记,给你的系统打补丁以修复内核任何潜在的bug。任何已经报告的内核bug,可能在最新的内核包中已经修复了。


安装

这里提供两种方法去安装Docker引擎。你可以使用安装
yum
包管理器进行安装。或者,你可以使用
curl
连接到
get.docker.com
网站进行安装。第二种方法执行一个安装脚本,底层其实也是通过
yum
包管理器进行安装。


使用 yum 安装

携带着
sudo
root
的权限登陆到你的机器。

确保你的当前的yum包都是最新的。
$ sudo yum update


添加 yum repo(仓库)。
$ cat >/etc/yum.repos.d/docker.repo <<-EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF


安装Docker 包。
$ sudo yum install docker-engine


启动Docker daemon(守护进程)。
$ sudo service docker start


通过运行一个测试镜像到一个容器里,核实安装是否成功。
$ 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/



使用脚本安装

携带着
sudo
root
的权限登陆到你的机器。

$ sudo yum update


执行 Docker 安装脚本。
$ curl -sSL https://get.docker.com/ | sh


这个脚本添加了
docker.repo
仓库并安装Docker。

启动 Docker daemon。
$ sudo service docker start


通过运行一个测试镜像到一个容器里,核实安装是否成功。
$ sudo docker run hello-world



创建一个 docker 组

docker
daemon 绑定到一个 Unix socket 替代一个 TCP 端口。默认情况下,Unix
socket 是归
root
用户所有,其他用户要在命令前面追加
sudo
才能访问。由此,
docker
daemon
总是作为
root
用户的专属。

为了避免每次使用命令的时候都要追加
sudo
,可以创建一个名为
docker
的Unix组并将非根用户添加进去。当
docker
daemon
启动时,通过
docker
组可以把Unix Socket的读写权限共享给组中的用户。

警告:
docker
组等同
root
用户;势必会对你的系统注入安全隐患,可以移步到 Docker
Daemon 攻击面 获取更多的相关信息。

创建
docker
组并添加你的用户:

使用
sudo
权限登陆到你的CentOS中。

创建
docker
组并添加你的用户。

sudo usermod -aG docker your_username


登出并重新登陆。

这样保证你的用户使用正确的权限运行。

通过执行不带
sudo
docker
命令来核实上述配置是否生效。
$ docker run hello-world



设置 docker daemon 自动启动

确保 Docker 在你的系统启动时跟随西东,可以执行如下指令:
$ sudo chkconfig docker on


如果你需要一个HTTP代理,为Docker运行时文件设置一个不同的目录或分区,或者其他的自定义需求,请参考customize your Systemd Docker daemon options


卸载

你可以使用
yum
删除Docker。

列出你已经安装的包。
$ yum list installed | grep docker
yum list installed | grep docker
docker-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


查找并删除所有用户创建的配置文件。
来源: <https://docs.docker.com/engine/installation/centos/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: