Linux安装Docker

Centos7&Ubuntu

Docker的基本组成

image-20201028163804155

镜像(image):

docker镜像就好比是一个模板,可以通过这个模板来创建容器服务,tomcat镜像--->run--->tomcat01容器(提供服务器),通过这个镜像可以创建多个容器(最终服务运行或者项目运行就是在容器中的)。

容器(contalner):

Docker利用容器技术,独立运行一个或者一个组应用,通过镜像来创建的。

启动,停止,删除,基本命令!

目前就可以把这个容器理解为就是一个简易的linux系统

仓库(repository):

仓库就是存放镜像的地方:

仓库分为公有仓库和私有仓库!

Docker Hub(默认是国外的)

阿里云。。。都有容器服务器(配置镜像加速!)

Centos安装Docker

 #系统版本
[root@rtehz8mx3309ifmh-1018237 ~]# 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"
帮助文档:https://docs.docker.com/engine/install/centos/
 #1.卸载旧的版本
 $ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
                 
 #2.需要的安装包
 $ sudo yum install -y yum-utils
 
 #3.设置镜像的仓库
 #默认是国外
 $ sudo yum-config-manager \
     --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
 #阿里云镜像
 $ sudo yum-config-manager \
     --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 
 #4.更新yum索引
 yum makecache fast 或 yum makecache
 #如果有问题可能要更新yum
 yum update
 
 
 #5.安装docker核心
 #方法一
 yum install docker-ce docker-ce-cli containerd.io
 
 #方法二
 yum install -y https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.13-3.1.el7.x86_64.rpm
 
 yum install docker-ce docker-ce-cli containerd.io
 
 #6.启动docker
 systemctl start docker
 docker version
 

命令

 docker run hello-world
 #查看下载的镜像
 docker images
 #卸载docker
 yum remove docker-ce docker-ce-cli containerd.io
 
 rm -rf /var/lib/docker
 #/var/lib/docker docker的默认工作路径

ubuntu安装docker

 #1.卸载之前的版本
 sudo apt-get remove docker docker-engine docker.io containerd runc
 
 #2.设置docker镜像
 #更新apt软件包索引并安装软件包以允许apt通过HTTPS使用存储库:
 sudo apt-get update
 #添加Docker的官方GPG密钥:
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
 #验证您现在是否拥有带有指纹的密钥:
 sudo apt-key fingerprint 0EBFCD88
 #设置镜像仓库:(使用阿里云镜像地址)
 sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
 
 #我执行到最后一步时,提示add-apt-repository 和 lsb_release 找不到 解决方法如下
 apt-get install software-properties-common
 sudo apt-get install lsb-core -y #较大非必要不安装
 
 
 #3.正式安装docker
 #更新apt软件包索引
 sudo apt-get update
 #安装最新版的docker
 sudo apt-get install docker-ce docker-ce-cli containerd.io
 
 #4启动
 service docker start
 #查看docker是否安装成功(利用查看版本来验证)
 docker version