【Docker了解下】(二) —— Docker安装(CentOS)

系统环境

  • 内核版本不能低于3.10版本
[root@ ~]# uname -a
Linux iZm5ee0h5tkrzzli5jd8z5Z 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  • 系统版本不能低于CentOS7且仅支持64位
[root@ ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.4.1708 (Core) 
Release:        7.4.1708
Codename:       Core

安装前提

系统要求

  • 安装Docker CE需要CentOS7或以上版本,Archived版本暂不支持。

  • 需要将centos-extras设置成enabled。

[root@ ~]# vim /etc/yum.repos.d/CentOS-Base.repo

centos-extras

  • 推荐使用overlay2存储驱动。

删除旧版本

新版本的Docker已经改名为docker-ce,如果之前系统已经安装了旧版本,需要删除。

[root@ ~]# yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine

安装Docker CE

Docker有三种安装方式

  • 通过在线仓库安装
  • 通过安装包安装
  • 通过脚本安装

一、通过在线仓库安装

设置仓库

1、安装依赖

[root@ ~]# yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

2、添加源

[root@ ~]# yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# 阿里云备用源:http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3、配置参数

[root@ ~]# yum-config-manager --enable docker-ce-edge
[root@ ~]# yum-config-manager --enable docker-ce-test

安装Docker CE

1、安装最新版Docker CE

[root@ ~]# yum install docker-ce

二、通过安装包安装

1、下载想要的版本的安装包 安装包官方下载连接

[root@ home]# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.0.ce-3.el7.x86_64.rpm

2、安装下载的安装包

[root@ home]# yum install /home/docker-ce-18.06.0.ce-3.el7.x86_64.rpm

安装包安装虽然会创建docker的用户组,但不会在用户组内创建用户。因此如果不是root权限,可以用以下命令添加到docker用户组方便以后操作。

[root@ home]# usermod -aG docker $USER

三、通过脚本安装

由于阿里云服务器无法访问脚本中的镜像源,这种方法暂时跳过。

四、验证Docker安装成功

1、启动Docker

[root@ home]# systemctl start docker

2、检查Docker是否安装成功

[root@ ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9db2ca6ccae0: Pull complete 
Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
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.
    (amd64)
 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

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

显示以上内容表示安装成功。

镜像加速器

如果出现下载镜像时一直超时无法下载,可以尝试以下方法:

/etc/docker/daemon.json中写入如下内容,保证json格式的正确(文件不存在则自己创建),这里因为使用的是阿里云服务器所以使用了阿里云容器镜像服务提供的加速器地址。

{
  "registry-mirrors": [
    "https://XXXXXXXX.mirror.aliyuncs.com"
  ]
}

再重启服务。

[root@ docker]# systemctl daemon-reload
[root@ docker]# systemctl restart docker
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值