by nolan grace

通过诺兰·格雷斯

如何使用Docker Swarm管理更多容器 (How to manage more containers with Docker Swarm)

Scaling beyond a single server is a an important feature to understand about containers. When you start using containers to make it easy to scale your application, things really start to get interesting. Imagine you have used Docker containers for development and testing. Now you’re ready to go live.

扩展到单个服务器之外是了解容器的一项重要功能。 当您开始使用容器来简化应用程序扩展时,事情开始变得很有趣。 想象一下,您已经使用Docker容器进行开发和测试。 现在您可以开始直播了。

How can you make sure your application has enough resources? If you go viral, how will you scale?

如何确保应用程序具有足够的资源? 如果病毒传播,您将如何扩展?

This is where you should start using a container orchestrator like Swarm. The same group that brought you Docker built Swarm. Swarm exists to manage Docker containers on a cluster of machines. Docker Swarm makes it easy to deploy, manage, and scale your containers.

这是您应该开始使用Swarm之类的容器协调器的地方。 带给您Docker的同一个团队构建了Swarm。 存在Swarm来管理机器集群上的Docker容器。 Docker Swarm使部署,管理和扩展容器变得容易。

In this article, we will walk though the basics of container orchestration on a cluster. We will discuss the features of Docker Swarm, including how to start a Swarm, deploy an application, and scale that application. If you are not familiar with Docker, take a look at my other articles.

在本文中,我们将介绍集群中容器编排的基础知识。 我们将讨论Docker Swarm的功能,包括如何启动Swarm,部署应用程序以及扩展该应用程序。 如果您不熟悉Docker,请参阅我的其他文章。

What is Docker?Starting your first containerCreating your first DockerfileBuilding your first imageMoving past one container

什么是Docker? 启动您的第一个容器 创建您的第一个Dockerfile 构建您的第一个映像 移动经过一个容器

Make your way back here when you feel ready.

准备好后,请回到这里。

You may have heard me call Swarm a container orchestrator. What do I mean by that? Swarm takes control of managing and organizing both the hosts and Docker containers running on your cluster.

您可能听说过我叫Swarm是一个容器协调器。 那是什么意思 Swarm控制着管理和组织集群中运行的主机和Docker容器的控制。

Think of Swarm as an application that understands how to run Docker commands. You tell it where all your Docker hosts are, what containers you want to run, and Swarm takes care of the rest. Swarm manages networking, access, the state of your containers, scaling services, load balancing, and even relocating containers if a host becomes unresponsive.

将Swarm视为了解如何运行Docker命令的应用程序。 您告诉它所有Docker主机在哪里,要运行什么容器,而Swarm负责其余的工作。 Swarm可以管理网络,访问,容器的状态,扩展服务,负载平衡,甚至在主机无响应时甚至可以重新放置容器。

In this article, we are going to start up a Docker Swarm on your local machine. With our local Swarm we will familiarize ourselves with the most common commands and deploy some services.

在本文中,我们将在本地计算机上启动Docker Swarm。 通过我们的本地Swarm,我们将熟悉最常见的命令并部署一些服务。

蜂拥而至 (Starting a swarm)

To get started, you will need to have Docker-CE installed. To help you install Docker on your machine, please take a look at the Docker-CE site.

首先,您需要安装Docker-CE。 为了帮助您在机器上安装Docker,请访问Docker-CE网站。

Once you have successfully installed Docker, starting up your first Docker Swarm is as easy as running one command. Open up your terminal or command line and run the command below.

成功安装Docker之后,启动第一个Docker Swarm就像运行一个命令一样简单。 打开终端或命令行,然后运行以下命令。

> docker swarm init

You have done it! You are running your first Swarm.

你完成了! 您正在运行第一个Swarm。

If you’re running this host on a cloud platform like AWS or in a server farm, adding more nodes to your swarm cluster is simple. Simply follow the instructions in the Docker Documentation on how to create a Swarm. This documentation will show you how to manually initialize and add nodes to a Docker Swarm cluster.

如果要在类似AWS的云平台上或服务器场中运行此主机,则向群集集群添加更多节点很简单。 只需遵循Docker文档中有关如何创建Swarm的说明即可 。 本文档将向您展示如何手动初始化节点并将节点添加到Docker Swarm集群。

Another option is to spin up your own Rancher cluster. After you set up Rancher, you can let it do the heavy lifting for you. Rancher is a service that I use when exploring the features of different container orchestrators. Rancher makes it easy to spin up a cluster of machines and start a container orchestrator of your choice. Rancher has a nice and interactive web dashboard that makes it easy to spin up different orchestrators including Swarm, Mesos, or Kubernetes.

另一个选择是启动自己的Rancher集群。 设置Rancher之后,可以让它为您完成繁重的工作。 Rancher是我在探索不同容器协调器功能时使用的一项服务。 通过Rancher,可以轻松启动一组机器并启动您选择的容器协调器。 Rancher拥有一个不错的交互式Web仪表板,可以轻松启动包括Swarm,Mesos或Kubernetes在内的不同协调器。

You can find information about Getting Started with Rancher and Using Rancher to Start a Swarm in the Rancher Documentation.

您可以在Rancher文档中找到有关Rancher入门和使用Rancher启动群的信息。

For the purposes of this article, we will stick to the one node running on your local machine. This will make it a lot easier to familiarize ourselves with Docker Swarm and the Swarm CLI.

就本文而言,我们将坚持在本地计算机上运行的一个节点。 这将使熟悉Docker Swarm和Swarm CLI变得容易得多。

部署成群 (Deploy to Swarm)

Now that you have your swarm running, lets start some containers! If you are familiar with Docker, deploying to Docker Swarm should be a piece of cake. The commands used to deploy services and stacks for Docker-CE are the same commands used for Docker Swarm.

现在您已经运行了,请启动一些容器! 如果您熟悉Docker,那么部署到Docker Swarm应该是小菜一碟。 用于为Docker-CE部署服务和堆栈的命令与用于Docker Swarm的命令相同。

To deploy the pintail-whoami docker image, run the command below.

要部署pintail-whoami docker映像,请运行以下命令。

> docker service create --name pintail-whoami -p 80:80 pintailai/pintail-whoami:0.0.1

Open your browers and go to http://localhost and you should see the page below.

打开浏览器,然后转到http:// localhost ,您应该看到下面的页面。

The command used to start this service may be exactly the same as Docker-CE, but things work a little differently when connected to a Swarm.

用于启动该服务的命令可能与Docker-CE完全相同,但是在连接到Swarm时,工作原理有所不同。

When running services in a Swarm, the biggest difference is the physical location of your running containers. Docker Swarm will start a container on any host where resources are available. So just because you start a container from one host does not mean that is where the container will run.

在Swarm中运行服务时,最大的不同是运行中的容器的物理位置。 Docker Swarm将在任何可用资源的主机上启动一个容器。 因此,仅因为从一台主机启动容器并不意味着容器将在其中运行。

So how do you access a service that could be started anywhere in your cluster?

那么,如何访问可以在集群中任何地方启动的服务?

Docker Swarm has a very useful tool to solve this problem called the Swarm routing mesh. The routing mesh manages ingress into your running containers. By default, Swarm makes all services accessible via their published port on each Docker host.

Docker Swarm有一个非常有用的工具来解决此问题,称为Swarm路由网格。 路由网格管理进入您正在运行的容器的入口。 默认情况下,Swarm可以通过每个Docker主机上已发布的端口访问所有服务。

Let’s say you have a Swarm containing three Docker Hosts. If you deploy a service to your Swarm published on port 80, it doesn’t matter from which host you access that port — you will be routed to your service.

假设您有一个包含三个Docker主机的Swarm。 如果将服务部署到在端口80上发布的Swarm中,则从哪个主机访问该端口都没有关系-您将被路由到服务。

In the real world, if you have a web application and a Rest API, you could deploy you web app on port 80 and your API on 8080. With that configuration, you can scale the number of containers running different parts of your application. But you can always be sure that port 80 on any node in the Swarm cluster will take you to the website, and port 8080 to the Rest API.

在现实世界中,如果您具有Web应用程序和Rest API,则可以在端口80上部署Web应用程序,而在8080上部署API。通过这种配置,您可以扩展运行应用程序不同部分的容器的数量。 但是,您始终可以确保Swarm群集中任何节点上的端口80会将您带到网站,而端口8080会将您带到Rest API。

The Swarm routing mesh has its pros and cons. This default configuration has its limitations, but it is designed to make getting started as easy as possible. As your applications get more complex, the routing mesh can be configured to behave differently and different services can be deployed to use different routing configurations. For more information, please take a look at the Swarm Mode routing mesh documentation.

Swarm路由网格具有其优点和缺点。 此默认配置有其局限性,但旨在使入门变得尽可能容易。 随着您的应用程序变得越来越复杂,可以将路由网格配置为不同的行为,并且可以部署不同的服务以使用不同的路由配置。 有关更多信息,请查看Swarm模式路由网状文档 。

扩展您的服务 (Scaling your service)

Now that we have a service running, let’s ramp thing up a bit!

现在我们已经有一个服务正在运行,让我们开始吧!

Imagine you are running your website on a Docker Swarm in production and your site starts trending on Hacker News. Your traffic triples and you need to handle the additional load. To triple the number of containers you are running, simply run the command below:

想象一下,您正在生产中的Docker Swarm上运行您的网站,并且您的网站开始在Hacker News上流行。 您的流量增加了两倍,您需要处理额外的负载。 要将您正在运行的容器数量增加三倍,只需运行以下命令:

> docker service scale pintail-whoami_pintail-whoami=3

Presto! Docker Swarm scales the number of replicas you are running and routes traffic to the containers. After the command above completes, head back to you the “Pintail.ai Docker Example” in your browser and click refresh a few times. You should see the number change as the routing mesh navigates you to different containers.

快点! Docker Swarm可扩展您正在运行的副本的数量,并将流量路由到容器。 上面的命令完成后,回到您浏览器中的“ Pintail.ai Docker Example”,然后单击几次刷新。 当路由网格将您导航到其他容器时,您应该看到数字更改。

Swarm makes scaling services easy so you can worry about bigger issues.

Swarm使扩展服务变得容易,因此您可以担心更大的问题。

清理 (Clean Up)

Now let’s clean up our containers and Swarm.

现在,让我们清理容器和Swarm。

To remove the pintail-whoami stack, run

要删除长尾辫叠叠,运行

> docker stack rm pintail-whoami

Be careful with this next command. If you are running anything else within the swarm, it will be deleted.

下一条命令要小心 。 如果您在群集中运行其他任何程序,它将被删除。

To delete your Swarm cluster, run

要删除Swarm集群,请运行

> docker swarm leave --force

So in this article, we started a Swarm Host, we discussed adding nodes to our cluster, we started and scaled a service, and we talked about the Swarm routing mesh. Hopefully this introduction will help you better wrap your brain around container orchestration and Docker Swarm.

因此,在本文中,我们启动了Swarm主机,讨论了将节点添加到集群中,启动并扩展了服务,并讨论了Swarm路由网格。 希望此介绍将帮助您更好地围绕容器编排和Docker Swarm学习。

This article barely scratches the surface of what is possible with containers and Swarm, but I hope it gives you some context to help you continue learning.

本文勉强介绍了容器和Swarm的功能,但我希望它能为您提供一些背景信息,以帮助您继续学习。

Please let me know if you have any comments, questions, or concerns in the comments. I am always open to feedback and would love to hear your suggestions. If you liked the article, please leave me lots of claps to let me know.

如果您有任何意见,问题或疑虑,请告诉我。 我一直乐于接受反馈,很想听听您的建议。 如果您喜欢这篇文章,请给我很多鼓掌让我知道。

翻译自: https://www.freecodecamp.org/news/how-to-manage-more-containers-with-docker-swarm-332b5fc4c346/

如何使用Docker Swarm管理更多容器相关推荐

  1. 在 Docker 中运行 MySQL:多主机网络下 Docker Swarm 模式的容器管理

    本文将以多主机网络环境为基础,探讨如何利用内置编排工具 Docker Swarm 模式对各主机上的容器加以管理. Docker Engine – Swarm 模式 在多台主机之上运行 MySQL 容器 ...

  2. docker swarm MySQL_容器与云|在 Docker 中运行 MySQL:多主机网络下 Docker Swarm 模式的容器管理...

    本文将以多主机网络环境为基础,探讨如何利用内置编排工具 Docker Swarm 模式对各主机上的容器加以管理. Docker Engine – Swarm 模式 在多台主机之上运行 MySQL 容器 ...

  3. 多主机网络下 Docker Swarm 模式的容器管理

    导读 本文将以多主机网络环境为基础,探讨如何利用内置编排工具 Docker Swarm 模式对各主机上的容器加以管理. Docker Engine – Swarm 模式 在多台主机之上运行 MySQL ...

  4. Docker基础讲解狂神笔记:容器数据卷,docker compose,docker swarm(2/2)未修订版欢迎留言补漏

    L06 容器数据卷 相对于01-05难度加大 什么是容器数据卷 Docker理念:将应用和环境打包成一个镜像! 程序要保存数据,数据并不能放在容器里面,因为一旦数据放在容器,误操作删除掉容器,数据也随 ...

  5. 论Docker swarm与Kubernetes孰强孰弱

    前言 有无数的辩论和讨论谈论Kubernetes和Docker.如果你没有深入研究,你会认为这两种开源技术都在争夺集装箱至上.让我们明确指出,Kubernetes和Docker Swarm不是竞争对手 ...

  6. 使用Docker Swarm搭建分布式爬虫集群

    转载自  使用Docker Swarm搭建分布式爬虫集群 在爬虫开发过程中,你肯定遇到过需要把爬虫部署在多个服务器上面的情况.此时你是怎么操作的呢?逐一SSH登录每个服务器,使用git拉下代码,然后运 ...

  7. docker 管理工具_详解Docker可视化管理工具shipyard--部署教程及功能展示

    概述 谈及docker,避免不了需要熟练的记住好多命令及其用法,对于熟悉shell.技术开发人员而言,还是可以接受的,熟练之后,命令行毕竟是很方便的,便于操作及脚本化.但对于命令行过敏.非技术人员,进 ...

  8. [416]使用Docker Swarm搭建分布式爬虫集群

    在爬虫开发过程中,你肯定遇到过需要把爬虫部署在多个服务器上面的情况.此时你是怎么操作的呢?逐一SSH登录每个服务器,使用git拉下代码,然后运行?代码修改了,于是又要一个服务器一个服务器登录上去依次更 ...

  9. 《docker+k8s微服务容器化实践》笔记2

    5-3 集群环境搭建_A  5-4 集群环境搭建_B  5-5 集群环境搭建_C 这次开始动手操作,首先是Mesos的安装,怎么来安装Mesos.源码:https://github.com/limin ...

最新文章

  1. 152. Leetcode 剑指 Offer 14- II. 剪绳子 II (贪心算法-基础题目)
  2. php 即时到账,paypal即时到账php实现代码
  3. Linux网站访问的电脑占CPU,详解Linux如何查看当前占用CPU或内存最多的几个进程...
  4. 华为注册鸿蒙商标与三海经,华为注册了一本《山海经》?除了鸿蒙商标,还有很多...
  5. Java程序员都要懂得知识点:反射
  6. yeoman+grunt/gulp+bower构建angular项目
  7. Android_组件_BroadcastReceiver基础
  8. 80386的内存分页机制
  9. phpstudy连接SQL Server 2008数据库 以及 php使用sql server出现乱码解决方式
  10. unity透明通道加颜色_Unity的Gamma颜色空间和Linear颜色空间的小研究
  11. RDKit | RDKit分子结构图的详细说明
  12. 5G虚拟专网七大典型行业案例!(附下载)
  13. Android增量更新
  14. 漏洞payload 靶机_以DVRF(路由器漏洞靶机)为例解读JEB固件漏洞利用-阿里云开发者社区...
  15. [汇编] 最简单的汇编程序
  16. 台湾Yahoo联手Mozilla 对抗Google
  17. 【数据集划分】误用shuffle,导致训练集和测试集掺混
  18. 【逆向工程】C/C++的反汇编表示详解(1)函数调用,栈平衡,变量与参数的内存布局
  19. 2019 南京 网络赛 B (二维偏序,树状数组离线)
  20. DeepCachNet A Proactive Caching Framework Based on Deep Learning in Cellular Networks论文阅读

热门文章

  1. 异常的捕获 try...catch java
  2. 泛型数组 List c# 1613647847
  3. linux-查看用户id-查看文件目录所有者-查看进程操作者
  4. python-turtle库-01
  5. Guava链式风格Ordering比较器实例
  6. 涉及反射/内省/泛型的优化实践
  7. 2016物联网大趋势搞不懂?别担心,CES为你指点迷津
  8. 1.Ehcache(01)——简介、基本操作
  9. Python基础(12)--模块
  10. Volume group VolGroup00 not found