在线安装

环境准备

1、Linux基础
2、CentOS 7
3、Xshell连接远程操作

环境查看

  1. #系统内核
  2. [root@Mi10Pro-C ~]# uname -r
  3. 3.10.0-229.el7.x86_64
  4. # 系统版本
  5. [root@Mi10Pro-C ~]# cat /etc/os-release
  6. NAME="Red Hat Enterprise Linux Server"
  7. VERSION="7.1 (Maipo)"
  8. ID="rhel"
  9. ID_LIKE="fedora"
  10. VERSION_ID="7.1"
  11. PRETTY_NAME="Red Hat Enterprise Linux Server 7.1 (Maipo)"
  12. ANSI_COLOR="0;31"
  13. CPE_NAME="cpe:/o:redhat:enterprise_linux:7.1:GA:server"
  14. HOME_URL="https://www.redhat.com/"
  15. BUG_REPORT_URL="https://bugzilla.redhat.com/"
  16. REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
  17. REDHAT_BUGZILLA_PRODUCT_VERSION=7.1
  18. REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
  19. REDHAT_SUPPORT_PRODUCT_VERSION="7.1"

安装

  1. # 1、卸载旧版本
  2. yum remove docker \
  3. docker-client \
  4. docker-client-latest \
  5. docker-common \
  6. docker-latest \
  7. docker-latest-logrotate \
  8. docker-logrotate \
  9. docker-engine
  10. # 2、安装需要的安装包
  11. yum install -y yum-utils
  12. # 3、设置镜像的仓库地址
  13. yum-config-manager \
  14. --add-repo \
  15. http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #阿里源
  16. https://download.docker.com/linux/centos/docker-ce.repo #默认的这个是国外源
  17. # 更新yum软件包的索引
  18. yum makecache fast
  19. # 3、安装docker引擎 docker-ce 社区 ee 企业版本
  20. yum -y install docker-ce docker-ce-cli containerd.io
  21. # 注意:最小化安装的可能会报错,原因是container-selinux版本过低
  22. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  23. 安装后重新安装docker
  24. # 4、启动docker
  25. systemctl start docker
  26. systemctl enable docker.service
  27. docker version
  28. # 5、测试hello world
  29. docker run hello-world
  30. # 6、查看下载的hello world镜像
  31. docker images
  32. # 7、卸载docker
  33. yum remove docker-ce docker-ce-cli containerd.io #卸载依赖
  34. rm -rf /var/lib/docker #删除资源,默认的工作路径/var/lib/docker

配置阿里云镜像加速服务

1、登录阿里云找到容器镜像服务

image.png

2、找到镜像加速地址

image.png3、配置使用

  1. #您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
  2. sudo mkdir -p /etc/docker
  3. sudo tee /etc/docker/daemon.json <<-'EOF'
  4. {
  5. "registry-mirrors": ["https://pvav6eq4.mirror.aliyuncs.com"]
  6. }
  7. EOF
  8. sudo systemctl daemon-reload
  9. sudo systemctl restart docker

Docker Run的流程和原理

image.png
image.png

比虚拟机更少的抽象层,比虚拟机少了引导部分启动,决定了他更加轻量快速

离线安装docker

一、基础环境

1、Docker版本:18.06.1 官方下载地址(打不开可能需要梯子)
2、百度云Docker 18.06.1地址:https://pan.baidu.com/s/1YdN9z72QutPkHBfLq06H1A 密码:dvvh
3、官方参考文档:https://docs.docker.com/install/linux/docker-ce/binaries/#install-static-binaries

二、Docker安装

1、下载

  1. wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.1-ce.tgz

2、解压

  1. tar -xvf docker-18.06.1-ce.tgz

3、将解压出来的docker文件内容移动到 /usr/bin/ 目录下

  1. cp docker/* /usr/bin/

4、将docker注册为service

  1. vim /etc/systemd/system/docker.service
  2. [Unit]
  3. Description=Docker Application Container Engine
  4. Documentation=https://docs.docker.com
  5. After=network-online.target firewalld.service``Wants=network-online.target`` ` `[Service]``Type=notify``# the default is not to use systemd for cgroups because the delegate issues still``# exists and systemd currently does not support the cgroup feature set required``# for containers run by docker``ExecStart=/usr/bin/dockerd``ExecReload=/bin/kill -s HUP $MAINPID``# Having non-zero Limit*s causes performance problems due to accounting overhead``# in the kernel. We recommend using cgroups to do container-local accounting.``LimitNOFILE=infinity``LimitNPROC=infinity``LimitCORE=infinity``# Uncomment TasksMax if your systemd version supports it.``# Only systemd 226 and above support this version.``#TasksMax=infinity``TimeoutStartSec=0``# set delegate yes so that systemd does not reset the cgroups of docker containers``Delegate=yes``# kill only the docker process, not all processes in the cgroup``KillMode=process``# restart the docker process if it exits prematurely``Restart=``on``-failure``StartLimitBurst=3``StartLimitInterval=60s`` ` `[Install]``WantedBy=multi-user.target

5、启动

  1. chmod +x /etc/systemd/system/docker.service #添加文件权限并启动docker
  2. systemctl daemon-reload #重新加载配置文件
  3. systemctl start docker #启动Docker
  4. systemctl enable docker.service #设置开机自启

6、验证

  1. systemctl status docker #查看Docker状态
  2. docker -v #查看Docker版本