首页 > 编程知识 正文

Centos7安装docker,centos7安装docker教程

时间:2023-05-03 09:18:14 阅读:282794 作者:1083

前提设置:关闭防火墙和网络管理,还有关闭selinux安全设置

[root@localhost ~]# systemctl stop NetworkManager #关闭网络管理[root@localhost ~]# systemctl stop firewalld #关闭防火墙[root@localhost ~]# systemctl disable NetworkManager #关闭开机自动开启网络管理[root@localhost ~]# systemctl disable firewalld #关闭开机自动开启防火墙[root@localhost ~]# vi /etc/selinux/config #编辑selinux安全设置为宽容模式... #省略内容SELINUX=permissive ... #省略内容 [root@localhost ~]# setenforce #设置临时关闭selinux安全usage: setenforce [ Enforcing | Permissive | 1 | 0 ] # 1代表开启 | 0代表关闭[root@localhost ~]# setenforce 0 #设置临时关闭seliux安全[root@localhost ~]# getenforce #查看seliux安全的状态 Permissive

根据官方文档:https://docs.docker.com/install/linux/docker-ce/centos/

1.卸载旧的版本docker或docker-engine

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

2.使用存储库安装, 由于官方存储库下载的比较慢,就使用清华大学镜像的存储库或者使用阿里云镜像的存储库

 2-1.安装存储库所需要的依赖包

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

2-2.使用清华大学镜像存储库或者阿里云镜像存储库

[root@localhost ~]# yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo 或者用阿里云镜像存储库yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3.使用CentOS7自带的yum包,用于安装docker所需要的依赖包

[root@localhost ~]# vi /etc/yum.repos.d/CentOS-Base.repo[base]name=CentOS-$releasever - Basemirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infragpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7[updates]name=CentOS-$releasever - Updatesmirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infragpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7[extras]name=CentOS-$releasever - Extrasmirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infragpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7[centosplus]name=CentOS-$releasever - Plusmirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infragpgcheck=1enabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

 4.安装docker

 

[root@localhost ~]# yum install docker-ce docker-ce-cli containerd.io

5.启动docker,并查看docker的版本

[root@localhost ~]# systemctl start docker #启动docker[root@localhost ~]# docker -v #查看docker版本Docker version 18.09.7, build 2d0083d[root@localhost ~]# docker info #查看docker详细信息Containers: 0 Running: 0 Paused: 0 Stopped: 0Images: 0Server Version: 18.09.7Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: trueLogging Driver: json-fileCgroup Driver: cgroupfsPlugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fbrunc version: 425e105d5a03fabd737a126ad93d62a9eeede87finit version: fec3683Security Options: seccomp Profile: defaultKernel Version: 3.10.0-862.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 4Total Memory: 3.685GiBName: localhostID: IVDD:BQR4:ASMV:YC4O:HSAI:35B4:DC7J:66H4:WPIV:OA27:GJE7:QS2YDocker Root Dir: /var/lib/dockerDebug Mode (client): falseDebug Mode (server): falseRegistry: https://index.docker.io/v1/Labels:Experimental: falseInsecure Registries: 127.0.0.0/8Live Restore Enabled: falseProduct License: Community Engine

 6.使用腾讯云提供的国内镜像源, 加速访问 Docker Hub,参考腾讯云实验手册:https://cloud.tencent.com/developer/labs/lab/10054

6-1.旧版的docker使用镜像加速器

[root@localhost ~]# echo "OPTIONS='--registry-mirror=https://mirror.ccs.tencentyun.com'" >> /etc/sysconfig/docker[root@localhost ~]# systemctl daemon-reload #重新加载

6-2.新版的docker使用镜像加速器,参考菜鸟:https://www.runoob.com/docker/centos-docker-install.html

[root@localhost ~]# vi /etc/docker/daemon.json #编辑镜像加速器{ "registry-mirrors": ["https://registry.docker-cn.com"]}[root@localhost ~]# systemctl restart docker #配置后重启服务

6-3.参考DaoCloud的镜像加速器:https://www.daocloud.io/mirror#accelerator-doc

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

7.启动路由转发,参考官方文档:https://docs.docker.com/network/bridge/

 7-1.临时设置启动路由转发

[root@localhost ~]# sysctl net.ipv4.conf.all.forwarding=1net.ipv4.conf.all.forwarding = 1[root@localhost ~]# iptables -P FORWARD ACCEPT #关闭了防火墙就不用设置策略

7-2.永久设置启动路由转发

[root@localhost ~]# vi /etc/sysctl.conf...net.ipv4.ip_forward = 1net.ipv4.conf.all.forwarding=1 #在最后添加[root@localhost ~]# sysctl -p #启动加载参数net.ipv4.conf.all.forwarding = 1

8. 测实安装docker

[root@localhost ~]# docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-world1b930d010525: Already exists Digest: sha256:41a65640635299bab090f783209c1e3a3f11934cf7756b09cb2f1e02147c6ed8Status: Downloaded newer image for hello-world:latestHello from Docker!This message shows that your installation appears to be working correctly....[root@localhost ~]# docker images #查看镜像REPOSITORY TAG IMAGE ID CREATED SIZEhello-world latest fce289e99eb9 6 months ago 1.84kB[root@localhost ~]# docker ps -a #查看所有容器CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES33c9caf11103 hello-world "/hello" 18 minutes ago Exited (0) 18 minutes ago recursing_ishizaka[root@localhost ~]# docker ps -aq #指定查看容器的ID33c9caf11103[root@localhost ~]# docker logs 33c9caf11103 #查看容器的标准输出(内容)Hello from Docker!This message shows that your installation appears to be working correctly....

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。