安装 EPEL
两种方式
直接安装:
yum install epel-release
还可以替换清华源
通过链接安装:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
可查看官方说明
更新下依赖软件
sudo yum update -y
安装 Docker
添加用户组
添加一个 docker
组
groupadd docker
将使用 docker
的用户添加进组里
useradd docker -g docker
将当期用户添加进组
sudo usermod -aG docker $USER
安装 Docker
CentOS7 以上系统,可通过 curl -sSL https://get.docker.com/ | sh
直接指向安装脚本,这里是用 yum
安装。
sudo yum -y install docker-io
执行 docker version
检查是否安装成功:
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
OS/Arch (client): linux/amd64
Get http:///var/run/docker.sock/v1.19/version: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
此时尚未启动 Docker Server 所以最后有提示。
镜像加速
目前国内已有几个成熟的镜像加速,这里以 DockerCn
为例:
CentOS6 通过编辑 /etc/sysconfig/docker
文件的 other_args
参数实现镜像加速。
# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker -d
other_args="--registry-mirror=https://registry.docker-cn.com"
DOCKER_CERT_PATH=/etc/docker
# Resolves: rhbz#1176302 (docker issue #407)
DOCKER_NOWARN_KERNEL_VERSION=1
# Location used for temporary files, such as those created by
# # docker load and build operations. Default is /var/lib/docker/tmp
# # Can be overriden by setting the following environment variable.
# # DOCKER_TMPDIR=/var/tmp
此示例仅适用于 CentOS6
,如果已经启动服务,需要重启服务 service docker restart
。
启动服务
启动 Docker 服务
service docker start
另附上停止和重启服务
service docker stop
service docker restart
检查安装
执行 docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
# /etc/sysconfig/docker
Git commit (server): 786b29d/1.7.1
OS/Arch (server): linux/amd64
执行 docker info
Containers: 0
Images: 0
Storage Driver: devicemapper
Pool Name: docker-202:2-1172437-pool
Pool Blocksize: 65.54 kB
Backing Filesystem: extfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 305.7 MB
Data Space Total: 107.4 GB
Data Space Available: 34.62 GB
Metadata Space Used: 733.2 kB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.147 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.117-RHEL6 (2016-12-13)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 2.6.32-358.el6.x86_64
Operating System: <unknown>
CPUs: 8
Total Memory: 15.55 GiB
Name: ecs-634b-0002
ID: IMEI:V37Q:FO5S:3GYL:X2UH:2ECU:V4RW:---------------------------
至此,安装完成!