Centos 安装Docker

先天条件

在CentOS中安装Docker 需要满足以下几个条件:

  • CPU 必须为64位;

  • Linux 内核必须在 3.10版本以上。
    可以使用 uname - a 命令获取 以上信息

    uname -a
    
  • 确保 yum 包更新到最新

    yum update
    

卸载docker旧版本

sudo yum remove docker \  
    docker-client \  
    docker-client-latest \  
    docker-common \  
    docker-latest \  
    docker-latest-logrotate \  
    docker-logrotate \  
    docker-selinux \  
    docker-engine-selinux \  
    docker-engine

安装相关工具类

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

添加软件源信息

(由于国内访问不到docker官方镜像的缘故 通过aliyun的源来完成)

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

更新并安装 Docker-CE

sudo yum makecache fast  
sudo yum -y install docker-ce

开启Docker服务

sudo systemctl start docker

配置阿里云的docker镜像库

因为国内无法访问dockerhub 点我获取阿里云加速地址

img
在阿里云开通容器镜像服务拿到加速地址在执行以下命令:

sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' {  "registry-mirrors": ["阿里云加速地址"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker 

验证docker

sudo docker run hello-world

出现以下内容则表示安装成功:

Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
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/

查看docker版本号

sudo docker version

官方安装地址

https://docs.docker.com/install/linux/docker-ce/centos/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值