系统相关
首页 > 系统相关> > 第五章 Centos7下安装Docker

第五章 Centos7下安装Docker

作者:互联网

一、查看系统内核版本号

1.查看系统内核版本号

[root@m01 ~]# uname -a
Linux m01 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

2.备份原来YUN源

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

3.更换YUM源

[root@m01 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

4.刷新yum源缓存

[root@m01 ~]# yum makecache

5.新机器更新系统

#
[root@alvin-test-os ~]# yum update -y --exclud=kernel*

二、安装依赖包

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

三、添加Docker镜像源

[root@m01 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

[root@m01 ~]# ll /etc/yum.repos.d/
total 12
-rw-r--r--. 1 root root 2523 Aug  6 00:39 CentOS-Base.repo
-rw-r--r--  1 root root 2640 Mar 16  2020 docker-ce.repo
-rw-r--r--. 1 root root  664 Aug  6 00:40 epel.repo

四、安装Docker

[root@m01 ~]# yum -y install docker-ce 

五、设置开机自启动

[root@m01 ~]# systemctl  enable  --now docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

六、验证服务

[root@m01 ~]# docker --version  
Docker version 20.10.2, build 2291f61

七、设置加速器

1.打开阿里云官网

2.选择 产品 --> 容器与中间件 --> 容器与镜像服务ACR --> 管理控制台 --> 镜像加速器

[root@m01 ~]# sudo mkdir -p /etc/docker
[root@m01 ~]# sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://8mh75mhz.mirror.aliyuncs.com"]
}
EOF
[root@m01 ~]# sudo systemctl daemon-reload
[root@m01 ~]# sudo systemctl restart docker

八、Docker第一个案例

[root@docker /]# docker run -d -P --rm nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
6ec7b7d162b2: Pull complete 
cb420a90068e: Pull complete 
2766c0bf2b07: Pull complete 
e05167b6a99d: Pull complete 
70ac9d795e79: Pull complete 
Digest: sha256:4cf620a5c81390ee209398ecc18e5fb9dd0f5155cd82adcbae532fec94006fb9
Status: Downloaded newer image for nginx:latest
c5938fd6c0f392b429e12a5ea5ba7ed1e27befe2dde1247c843f70ca3d9db138
[root@docker /]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED              STATUS              PORTS                   NAMES
c5938fd6c0f3   nginx     "/docker-entrypoint.…"   About a minute ago   Up About a minute   0.0.0.0:49153->80/tcp   naughty_buck

标签:repo,--,Centos7,第五章,yum,m01,Docker,root,docker
来源: https://www.cnblogs.com/jhno1/p/15261937.html