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 组
dockerdaemon 绑定到一个 Unix socket 替代一个 TCP 端口。默认情况下,Unix
socket 是归
root用户所有,其他用户要在命令前面追加
sudo才能访问。由此,
dockerdaemon
总是作为
root用户的专属。
为了避免每次使用命令的时候都要追加
sudo,可以创建一个名为
docker的Unix组并将非根用户添加进去。当
dockerdaemon
启动时,通过
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/>
相关文章推荐
- Linux_文件系统、磁盘分区_RHEL7
- Centos安装smokeping教程
- Linux_LVM、RAID_RHEL7
- 利用scp 在linux之间传输文件
- kill命令---Linux学习笔记
- CentOS7执行ifconfig Command not found 未找到命
- linux系统目录结构
- CentOS 6 到 CentOS 7 的升级过程
- Linux常用命令大全
- linux 下QT安装
- Linux中内存相关概念与内存申请的几种方式
- ps命令---Linux学习笔记
- Linux_使用putty上传文件到linux系统
- 使用yum在centos下安装最新版的ffmpeg
- Centos 6.5 下IF.SVNAdmin 安装
- linux C 学习 简单字符串逆序输出
- Linux(CentOS6) 调整 /home 挂载 分区大小
- [Linux学习笔记] Linux系统引导流程(一)
- 理解 pkg-config 工具(linux编译辅助工具)
- linux配置直接用VIM默认打开文件