ToB企服应用市场:ToB评测及商务社交产业平台

标题: Docker(1) [打印本页]

作者: 飞不高    时间: 2022-8-9 14:42
标题: Docker(1)
简介

是什么?

确保应用能够在这些环境中运行和通过质量检测.并且在部署过程中不出现令人头疼的版本、配置问题,也无需重新编写代码和进行故障修复.
Docker之所以发展如此迅速,也是因为它对此给出了一个标准化的解决方案-----系统平滑移植,容器虚拟化技术。
解决了运行环境和配置问题的软件容器,方便做持续集成并有助于整体发布的容器虚拟化技术。
能干嘛?

一次构建、随处运行
去哪下?

docker官网:http://www.docker.com
Docker Hub官网: https://hub.docker.com/
Docker 的基本组成

镜像(image)

image 文件生成的容器实例,本身也是一个文件,称为镜像文件.

容器(container)

一个容器运行一种服务,当我们需要的时候,就可以通过docker客户端创建一个对应的运行实例,也就是我们的容器.

仓库(repository)

仓库(Repository)是集中存放镜像文件的场所。

总结

Docker 本身是一个容器运行载体或称之为管理引擎。我们把应用程序和配置依赖打包好形成一个可交付的运行环境,这个打包好的运行环境就是image镜像文件。只有通过这个镜像文件才能生成Docker容器实例(类似Java中new出来一个对象)。
image文件可以看作是容器的模板。Docker 根据 image 文件生成容器的实例。同一个 image 文件,可以生成多个同时运行的容器实例。
镜像文件 image 文件生成的容器实例,本身也是一个文件,称为镜像文件.
工作原理

Docker 是一个Client-Server 结构的系统架构,Docker 守护进程运行在主机上,然后通过 Socker 连接从客户端访问,守护进程从客户端接受命令并管理运行在主机上的容器,容器,是一个运行时环境,就是一个个集装箱.
Docker 是一个 C/S 模式的架构,后端是一个松耦合架构,众多模块各司其职。
Docker运行的基本流程:

安装

https://docs.docker.com/engine/install/centos/ 官网安装操作指南
确认虚拟机版本是 CentOS7 及以上版本
  1. [root@localhost ~]# cat /etc/redhat-release
  2. CentOS Linux release 7.9.2009 (Core)
  3. [root@localhost ~]# uname -r
  4. 3.10.0-1160.59.1.el7.x86_64
复制代码
卸载旧版
  1. yum remove docker \
  2.                   docker-client \
  3.                   docker-client-latest \
  4.                   docker-common \
  5.                   docker-latest \
  6.                   docker-latest-logrotate \
  7.                   docker-logrotate \
  8.                   docker-engine
复制代码
安装 gcc 相关
  1. [root@localhost ~]# yum -y install gcc
  2. [root@localhost ~]# yum -y install gcc-c++
复制代码
设置存储库
官网推荐的是外网的地址,下载速度慢且会出现网络超时的问题.
  1. [root@localhost ~]# yum install -y yum-utils
  2. [root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
复制代码
建立元数据缓存
  1. [root@localhost ~]# yum makecache fast
复制代码
安装 Docker
  1. [root@localhost ~]# yum install docker-ce docker-ce-cli containerd.io
复制代码
启动 Docker
  1. [root@localhost ~]# systemctl start docker
复制代码
运行 hello-world
  1. [root@localhost ~]# docker run hello-world
  2. Hello from Docker!
  3. This message shows that your installation appears to be working correctly.
  4. To generate this message, Docker took the following steps:
  5. 1. The Docker client contacted the Docker daemon.
  6. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  7.     (amd64)
  8. 3. The Docker daemon created a new container from that image which runs the
  9.     executable that produces the output you are currently reading.
  10. 4. The Docker daemon streamed that output to the Docker client, which sent it
  11.     to your terminal.
  12. To try something more ambitious, you can run an Ubuntu container with:
  13. $ docker run -it ubuntu bash
  14. Share images, automate workflows, and more with a free Docker ID:
  15. https://hub.docker.com/
  16. For more examples and ideas, visit:
  17. https://docs.docker.com/get-started/
复制代码
修改镜像加速器
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
[code]sudo mkdir -p /etc/dockersudo tee /etc/docker/daemon.json




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4