docker 学习一 docker的安装与卸载

一、docker的安装

docker的安装要参考官方文档:https://docs.docker.com/中的 Download and install

 

在选择安装的软件时注意,我们安装的时Docker Engine(docker引擎)。在docker中选择CentOS系统。

 

docker的安装步骤

1、卸载老版本的docker

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

 

2、安装yum工具

Install the yum-utils package (which provides the yum-config-manager utility) and set up the repository.

yum install -y yum-utils

 

3、然后更新本地镜像源

使用yum-utils中的yum-config-manager工具来安装本地镜像源

# 设置docker镜像源
yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

 

4、新yum软件包索引

yum makecache fast

 

5、安装Docker CE

docker-ce ce代表社区版

docker-ce-cli 社区版的客户端

yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

 

6、启动docker

systemctl start docker

 

7、运行docker

docker run hello-world

 

/var/lib/docker是docker的工作目录

二、docker的卸载

 

1、Uninstall the Docker Engine, CLI, containerd, and Docker Compose packages:

yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras

 

2、Images, containers, volumes, or custom configuration files on your host aren’t automatically removed. To delete all images, containers, and volumes:

rm -rf /var/lib/docker
rm -rf /var/lib/containerd

三、阿里云镜像加速

登录阿里云系统,在阿里云提供的服务里面有一个镜像服务

 

 

点进去之后,有一个容器加速服务

 

 

选择CentOS加速配置

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://cenrnkg6.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

 

四、运行原理

docker run hello-world的运行原理是怎么样的?

先看dokcer的结构图

 

在上图中,docker有三大组件

镜像(Image):Docker 镜像(Image),就相当于是一个 root 文件系统。比如官方镜像 ubuntu:16.04 就包含了完整的一套 Ubuntu16.04 最小系统的 root 文件系统。

容器(Container):镜像(Image)和容器(Container)的关系,就像是面向对象程序设计中的类和对象一样,镜像是静态的定义,容器是镜像运行时的实体。容器可以被创建、启动、停止、删除、暂停等。

仓库(Repositor):仓库可看成一个代码控制中心,用来保存镜像。

 

首先Docker尝试去本地查找hello-world镜像,结果没找到(因为是第一次下载,本地肯定没有)

然后Docker去远程仓库拉取hello-world镜像,找到了,于是开始下载

下载完成后,根据tomcat镜像启动容器,并打印出容器ID

posted @ 2023-05-06 21:59  阿瞒123  阅读(108)  评论(0编辑  收藏  举报