编辑
2022-08-31
编程
00

目录

1. Docker 概述
2. Dokcer 安装
2.1 Docker 的基本组成
2.2 安装 docker
服务器环境:
安装与卸载
1. 卸载旧的版本
2. 需要的安装包
3. 设置镜像仓库
4. 更新 yuml 索引
5. 安装docker相关的
6. 启动 docker
7. 运行 hello-world
8. 查看下载的镜像
9. 卸载:卸载依赖
10. 卸载:删除资源
阿里云镜像加速
华为云镜像加速

1. Docker 概述

  • 官网: https://www.docker.com/

  • 文档: https://docs.docker.com/

  • 仓库: https://hub.docker.com/

  • docker 的产生:

    • 开发、测试、生产环境一致
    • 环境配置简化,项目与环境打包
    • 环境隔离,最大效率使用服务器
  • docker 的历史:

    • 2010:dotCloud -> pass 云计算服务,LXC有关的容器技术整合命名为 docker
    • 2013:docker 开源
    • 20140409: docker 1.0 发布
  • 目标:

    • 应用更快速的交付和部署
    • 更便捷的升级和扩缩容
    • 更简单的系统运维
    • 更高效的计算资源利用

2. Dokcer 安装

2.1 Docker 的基本组成

DockerArchitectureDiagram.svg

  • 镜像(image):

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

  • 容器(container):

Docker利用容器技术,独立运行一个或者一个组应用,通过镜像来创建的。 启动,停止,删除,基本命令 ! 目前就可以把这个容器理解为就是一个简易的linux系统

  • 仓库(repository):

仓库就是存放镜像的地方 ! 仓库分为公有仓库和私有仓库! Docker Hub( 默认是国外的 ) 阿里云....都有容器服务器( 配置镜像加速 ! )

2.2 安装 docker

这里直接使用 华为云 的试用服务器- -

服务器环境:

shell
# 系统内核 4.18 [root@hecs-152658 ~]# uname -r 4.18.0-348.7.1.el8_5.x86_64 # 系统版本 [root@hecs-152658 ~]# cat /etc/os-release NAME="CentOS Linux" VERSION="8 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="8" PLATFORM_ID="platform:el8" PRETTY_NAME="CentOS Linux 8 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:8" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-8" CENTOS_MANTISBT_PROJECT_VERSION="8" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="8"

安装与卸载

帮助文档:https://docs.docker.com/engine/install/

1. 卸载旧的版本
shell
[root@hecs-152658 ~]# yum remove docker \ > docker-client \ > docker-client-latest \ > docker-common \ > docker-latest \ > docker-latest-logrotate \ > docker-logrotate \ > docker-engine No match for argument: docker No match for argument: docker-client No match for argument: docker-client-latest No match for argument: docker-common No match for argument: docker-latest No match for argument: docker-latest-logrotate No match for argument: docker-logrotate No match for argument: docker-engine No packages marked for removal. Dependencies resolved. Nothing to do. Complete!
2. 需要的安装包
shell
[root@hecs-152658 ~]# sudo yum install -y yum-utils Last metadata expiration check: 0:05:41 ago on Fri 28 Jul 2021 04:54:36 PM CST. Package yum-utils-4.0.21-3.el8.noarch is already installed. Dependencies resolved. Nothing to do. Complete!
3. 设置镜像仓库
shell
# 默认是国外的,设置程阿里云的仓库 # yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo [root@hecs-152658 ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo Adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4. 更新 yuml 索引
shell
# 如果是 centos7 需要 yum makecache fast [root@hecs-152658 ~]# yum makecache CentOS-8 - AppStream 52 kB/s | 4.3 kB 00:00 CentOS-8 - Base 44 kB/s | 3.9 kB 00:00 CentOS-8 - Extras 19 kB/s | 1.5 kB 00:00 Copr repo for caddy owned by @caddy 1.5 kB/s | 3.3 kB 00:02 Docker CE Stable - x86_64 66 kB/s | 3.5 kB 00:00 Extra Packages for Enterprise Linux 8 - x86_64 9.3 kB/s | 4.7 kB 00:00 Extra Packages for Enterprise Linux Modular 8 - 4.1 kB/s | 3.0 kB 00:00 Metadata cache created.
5. 安装docker相关的
shell
# yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin [root@hecs-152658 ~]# yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin 省略... Complete!
6. 启动 docker
shell
[root@hecs-152658 ~]# sudo systemctl start docker [root@hecs-152658 ~]# docker -v Docker version 24.0.5, build ced0996
7. 运行 hello-world
shell
[root@hecs-152658 ~]# sudo docker run hello-world # 本地镜像获取(获取不到) Unable to find image 'hello-world:latest' locally # 拉取远程镜像 latest: Pulling from library/hello-world 719385e32844: Pull complete Digest: sha256:926fac19d22aa2d60f1a276b66a20eb765fbeea2db5dbdaafeb456ad8ce81598 Status: Downloaded newer image for hello-world:latest # 运行 hello-world Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
8. 查看下载的镜像
shell
[root@hecs-152658 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 9c7a54a9a43c 2 months ago 13.3kB
9. 卸载:卸载依赖
shell
sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
10. 卸载:删除资源
shell
sudo rm -rf /var/lib/docker sudo rm -rf /var/lib/containerd

阿里云镜像加速

aliyun_registry.png

华为云镜像加速

hwy_registry.png

本文作者:Yui_HTT

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!