Docker在CentOS安装文档

简介:

Docker在CentOS安装手册

这篇文档是通过Docker自己管理的发布版本包来指导你安装部署,使用这些包能确保您安装最新的Docker版本,

先决条件

Docker 需要一个64位操作系统CentOS,同时,您的内核(kernel)版本至少是3.10。

检查您当前内核的版本,打开一个终端(terminal),使用命令uname -r 来展示你的内核版本

$ uname -r
3.10.0-229.el7.x86_64

最后,建议你的系统打上最新的补丁,保证最新内核版本上已报告出来的kernel bugs都被修复啦

安装

有两种方式来安装Docker容器(Docker Engine)。你可以使用yum安装包管理器。或者使用curl通过站点get.docker.com来满足
自动化安装,第二种方法运行的安装脚本内部同样也是运用yum的方式。

YUM安装方式(Install with yum)

1.使用有sudo权限或者root权限的用户登录服务器。

2.确保你已有的yum包更新到最新版本

$ sudo yum update

3.添加yum仓库

× Linux CentOS 7 添加仓库方式

$ 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

× Linux CentOS 6 添加仓库方式

$ cat >/etc/yum.repos.d/docker.repo <<-EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/6
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

4.安装Docker部署包

$ sudo yum install docker-engine

5.启动Docker进程

$ sudo service docker start

6.为了验证docker被正确安装,我们通过在容器(container)中运行一个测试镜像来检验

$ 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 it
            to 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/

脚本安装方式(Install with the script)

1.使用有sudo权限或者root权限的用户登录服务器。

2.确保你已有的yum包更新到最新版本

$ sudo yum update

3.运行Docker安装脚本

$ curl -sSL https://get.docker.com/ | sh

这个脚本会添加docker.repo知识仓库,然后安装Docker。

4.启动Docker进程

$ sudo service docker start

5.为了验证docker被正确安装,我们通过在容器(container)中运行一个测试镜像来检验

$ sudo docker run hello-world

创建Docker组

Docker绑定Unix套接字来替换TCP端口。默认Unix套接字由root用户或者其他有sudo权限的用户拥有。由于这个原因Docker进程总是以root用户来运行。

当你使用Docker命令的时候避免你使用sudo命令,可以创建一个Unix用户组叫做docker然后把用户添加进去。当Docker进程开启后,它就可以被Docker用户组拥有,且具有读写权限。

警告:docker用户组相当于root用户组,对于你的系统产生多大的安全影响,细节
请查看Docker Daemon Attack Surface

创建Docker用户组并且添加用户

1.使用有sudo权限的用户登录CentOS

2.创建Docker用户组并且添加用户

sudo usermod -aG docker your_usernam

3.注销并重新登录

4.通过不用sudo命令验证你的docker操作

$ docker run hello-world

自启动docker进程

为了能在系统引导时启动docker进程,请做如下操作:

$ sudo chkconfig docker on

卸载

你可以通过yum卸载Docker软件

1.列出你安装过的包

$ 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

2.移除安装包

$ sudo yum -y remove docker-engine.x86_64

这个命令并没有移除镜像,容器和卷和你的主机上配置过的配置文件

3.删除所有的镜像,容器和卷,如下:

$ rm -rf /var/lib/docker

4.定位和删除用户配置过的配置文件

相关文章
|
4月前
|
Linux Docker 容器
CentOS7离线安装Docker
CentOS7离线安装Docker
305 0
|
4月前
|
Linux 开发工具 Docker
Docker dockerfile 案例:centos 支持 vim
Docker dockerfile 案例:centos 支持 vim
50 0
|
4月前
|
Linux Docker 容器
|
20天前
|
Linux Shell 开发工具
CentOS8中Docker安装及部署
CentOS8中Docker安装及部署
67 0
|
30天前
|
关系型数据库 MySQL 数据库
虚拟机Linux-Centos系统网络配置常用命令+Docker 的常用命令
虚拟机Linux-Centos系统网络配置常用命令+Docker 的常用命令
34 0
|
1月前
|
存储 弹性计算 Linux
阿里云ECS(CentOS镜像)安装docker
阿里云ECS(CentOS镜像)安装docker
374 0
|
3月前
|
存储 Linux 网络安全
Linux(CentOs7) --- 安装Docker容器
Linux(CentOs7) --- 安装Docker容器
160 1
|
3月前
|
存储 Linux 网络安全
Centos6.5安装/运行/启动/登录docker
Centos6.5安装/运行/启动/登录docker
93 0
|
4月前
|
Linux 数据库 数据安全/隐私保护
猿创征文|Linux centos7下利用docker快速部署SQLserver测试学习环境
猿创征文|Linux centos7下利用docker快速部署SQLserver测试学习环境
80 0
|
4月前
|
Linux Docker 容器
CentOS7 Install Docker Compose
CentOS7 Install Docker Compose