当前位置:   article > 正文

Docker环境安装教程_安装docker环境

安装docker环境

Docker要求Linux内核不低于 3.10 ,使用 CentOS 7及以上即可

uname -a 查看内核信息

Docker 分为 CE 和 EE 两大版本 我们安装CE社区版本即可

原先如果有安装可以使用下面命令卸载

 sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

安装 yum-utils

yum install -y yum-utils
  • 1
[root@node01 ~]# yum install -y yum-utils
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Determining fastest mirrors
epel                                                                                                                                                                          | 4.7 kB  00:00:00     
extras                                                                                                                                                                        | 2.9 kB  00:00:00     
os                                                                                                                                                                            | 3.6 kB  00:00:00     
updates                                                                                                                                                                       | 2.9 kB  00:00:00     
(1/5): epel/7/x86_64/group_gz                                                                                                                                                 |  98 kB  00:00:00     
(2/5): epel/7/x86_64/updateinfo                                                                                                                                               | 1.0 MB  00:00:00     
(3/5): extras/7/x86_64/primary_db                                                                                                                                             | 249 kB  00:00:00     
(4/5): updates/7/x86_64/primary_db                                                                                                                                            |  17 MB  00:00:01     
(5/5): epel/7/x86_64/primary_db                                                                                                                                               | 7.0 MB  00:00:01     
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

设置docker镜像源,这里选择阿里云镜像

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  • 1
[root@node01 ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
#查看是否添加成功

[root@node01 yum.repos.d]# cat /etc/yum.repos.d/docker-ce.repo |grep aliyun
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/stable
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/stable
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/test
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/test
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/test
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/nightly
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/nightly
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/nightly
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

安装docker

这里需要等待一段时间

 yum install -y docker-ce
  • 1
[root@node01 yum.repos.d]# docker version
Client: Docker Engine - Community
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:04:24 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

这里还没有启动报一小段错,需要启动一下
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

启动docker

可以选择关闭防火墙,不关闭也没关系,后面搭建k8s还是建议关闭

systemctl stop firewalld
#禁止开开机启动
systemctl disable firewalld
查看状态
systemctl status firewalld
  • 1
  • 2
  • 3
  • 4
  • 5
systemctl start docker
#开机自动启动
systemctl enable docker
  • 1
  • 2
  • 3

再次查看version

[root@node01 ~]# docker version 
Client: Docker Engine - Community
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:04:24 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 18:02:38 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.9
  GitCommit:        1c90a442489720eec95342e1789ee8a5e1b9536f
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

配置镜像加速

需要注册一个阿里云账号,用自己的,也可以用别人的。

注册地址

https://cr.console.aliyun.com/cn-beijing/instances

选择镜像工具->镜像加速器->选择对应版本 我这里选择centos
在这里插入图片描述

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://49w1xpkl.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/176821
推荐阅读
相关标签
  

闽ICP备14008679号