小言_互联网的博客

Docker 概述

274人阅读  评论(0)

系列文章目录



前言

Docker是为开发、运行应用而生的开放的平台。Docker使你可以将应用从依赖中分离,使你可以快速的释放软件。有了Docker你可以像管理管理你的应用一样管理依赖。同通过docker,你可以快速完成写代码、运行、分发等一些列操作。


Docker平台

Docker提供一种称为容器的若隔离环境,再此环境中可以打包和运行应用。隔离和安全的环境允许你在同一主机上同时运行多个容器。容器是轻量级的,不依赖主机环境,并且它包含运行应用的所有依赖。即便是在开发中,容器也支持轻松多人分享。

Docker 提供管理容器生命周期的工具和平台:

  • 使用容器开发应用和及组件
  • 容器是分发、测试应用的一个单元
  • 准备就绪后,将应用程序部署到生产环境中,作为容器或协调服务。无论您的生产环境是本地数据中心、云提供商还是两者的混合,这都是一样的。

用Docker可以做什么

快速连续交付应用

响应式部署和扩展

轻量级的虚拟机
Docker重量轻,速度快。它为基于虚拟机管理程序的虚拟机提供了一种可行、经济高效的替代方案,因此您可以使用更多的服务器容量来实现业务目标。Docker非常适合高密度环境和中小型部署,因为您需要用更少的资源做更多的事情。

Docker架构

Docker使用 Client-Server架构。Docker客户端与Docker守护进程对话,后者负责构建、运行和分发Docker容器。Docker客户端和守护程序可以在同一系统上运行,也可以将Docker客户端连接到远程Docker守护程序。Docker客户端和守护进程通过UNIX套接字或网络接口使用REST API进行通信。另一个Docker客户端是Docker Compose,它允许您处理由一组容器组成的应用程序

The Docker daemon

监听Docker API请求,管理Docker对象。
与其他守护进程通讯管理Docker服务。

The Docker client

用户通过Docker客户端与Docker 交互

Docker Desktop

它是个安装程序、程序管理器。
Docker Desktop includes the Docker daemon (dockerd), the Docker client (docker), Docker Compose, Docker Content Trust, Kubernetes, and Credential Helper. For more information, see Docker Desktop.

Docker registries

A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker is configured to look for images on Docker Hub by default. You can even run your own private registry.

When you use the docker pull or docker run commands, the required images are pulled from your configured registry. When you use the docker push command, your image is pushed to your configured registry.

Docker objects

Images

An image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization. For example, you may build an image which is based on the ubuntu image, but installs the Apache web server and your application, as well as the configuration details needed to make your application run.

You might create your own images or you might only use those created by others and published in a registry. To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the image. When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt. This is part of what makes images so lightweight, small, and fast, when compared to other virtualization technologies.

Containers

A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.

By default, a container is relatively well isolated from other containers and its host machine. You can control how isolated a container’s network, storage, or other underlying subsystems are from other containers or from the host machine.

A container is defined by its image as well as any configuration options you provide to it when you create or start it. When a container is removed, any changes to its state that are not stored in persistent storage disappear.

Example docker run command
以下命令运行一个ubuntu容器,以交互方式连接到本地命令行会话,并运行/bin/bash。

$docker run -i -t ubuntu /bin/bash
When you run this command, the following happens (assuming you are using the default registry configuration):

  1. If you do not have the ubuntu image locally, Docker pulls it from your configured registry, as though you had run docker pull ubuntu manually.

  2. Docker creates a new container, as though you had run a docker container create command manually.

  3. Docker allocates a read-write filesystem to the container, as its final layer. This allows a running container to create or modify files and directories in its local filesystem.

  4. Docker creates a network interface to connect the container to the default network, since you did not specify any networking options. This includes assigning an IP address to the container. By default, containers can connect to external networks using the host machine’s network connection.

  5. Docker starts the container and executes /bin/bash. Because the container is running interactively and attached to your terminal (due to the -i and -t flags), you can provide input using your keyboard while the output is logged to your terminal.

  6. When you type exit to terminate the /bin/bash command, the container stops but is not removed. You can start it again or remove it.


总结

docker 像一个轻量化的虚拟机。
用户通过client与docker进行交互。
从registry中pull镜像,通过镜像创建容器,应用运行在容器中。

https://docs.docker.com/get-started/overview/
docker 入门


转载:https://blog.csdn.net/surfaceyan/article/details/128460706
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场