linux安装docker,超简单!

杀马特。学长 韩版系。学妹 提交于 2020-12-13 12:41:52
  • 环境说明

    我们使用的是 CentOS 7 (64-bit)

    目前,CentOS 仅发行版本中的内核支持 Docker。

    Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。

    查看自己的内核:

uname -r 命令用于打印当前系统相关信息(内核版本号、硬件架构、主机名称和操作系统类型

等)。

[root@root1 yum.repos.d]# uname -r
3.10.0-514.26.2.el7.x86_64

查看版本信息:

命令:  cat /etc/os-release

 

[root@root1 yum.repos.d]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

[root@root1 yum.repos.d]# 

安装步骤

1、官网安装参考手册:https://docs.docker.com/engine/install/centos/

2、确定你是CentOS7及以上版本,我们已经做过了

3、yum安装gcc相关环境(需要确保 虚拟机可以上外网 )

 

yum -y install gcc 
yum -y install gcc-c++

4、卸载旧版本

命令:

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

5、安装需要的软件包

命令:

yum install -y yum-utils

6、设置镜像仓库

手工创建一个文件 docker.repo 文件, 文件放到 /etc/yum.repos.d 这个目录下, 内容如下面代码-附件

 

[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

 

7、更新yum软件包索引

yum makecache fast

8、安装 Docker CE

yum install docker-ce docker-ce-cli containerd.io

9、启动 Docker

systemctl start docker

/////////////////////////////特别情况/////////////////////////////////

假如出现错误如:   No more mirrors to try.

可能原因:可能是不正常删除造成的

解决方法: 命令:

yum clean all
yum makecache
yum -y update

然后重新安装

///////////////////////////特别情况结束/////////////////////////////////////////////////////////

10、测试命令

docker version 

docker run hello-world 

docker images 

 

11、卸载

systemctl stop docker 
yum -y remove docker-ce docker-ce-cli containerd.io
rm -rf /var/lib/docker

阿里云镜像加速

1、介绍:https://www.aliyun.com/product/acr

2、注册一个属于自己的阿里云账户(可复用淘宝账号)

3、进入管理控制台设置密码,开通

4、查看镜像加速器自己的

 

5、配置镜像加速

sudo mkdir -p /etc/docker  
sudo tee /etc/docker/daemon.json <<-'EOF' 
{ 
"registry-mirrors": ["https://qiyb9988.mirror.aliyuncs.com"] 
}
EOF
sudo systemctl daemon-reload 
sudo systemctl restart docker

测试 HelloWorld

1、启动hello-world

docker run hello-world

 

 

 

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!