目录搜索
ComposeAbout versions and upgrading (Compose)ASP.NET Core + SQL Server on Linux (Compose)CLI environment variables (Compose)Command-line completion (Compose)Compose(组成)Compose command-line reference(组合命令行参考)Control startup order (Compose)Django and PostgreSQL (Compose)Docker stacks and distributed application bundles (Compose)docker-compose build(docker-compose构建)docker-compose bundledocker-compose configdocker-compose createdocker-compose downdocker-compose eventsdocker-compose execdocker-compose helpdocker-compose imagesdocker-compose killdocker-compose logsdocker-compose pausedocker-compose portdocker-compose psdocker-compose pulldocker-compose pushdocker-compose restartdocker-compose rmdocker-compose rundocker-compose scaledocker-compose startdocker-compose stopdocker-compose topdocker-compose unpausedocker-compose upEnvironment file (Compose)Environment variables in ComposeExtend services in ComposeFrequently asked questions (Compose)Getting started (Compose)Install ComposeLink environment variables (deprecated) (Compose)Networking in ComposeOverview of Docker ComposeOverview of docker-compose CLIQuickstart: Compose and WordPressRails and PostgreSQL (Compose)Sample apps with ComposeUsing Compose in productionUsing Compose with SwarmEngine.NET Core application (Engine)About images, containers, and storage drivers (Engine)Add nodes to the swarm (Engine)Apply custom metadata (Engine)Apply rolling updates (Engine)apt-cacher-ngBest practices for writing Dockerfiles (Engine)Binaries (Engine)Bind container ports to the host (Engine)Breaking changes (Engine)Build your own bridge (Engine)Configure container DNS (Engine)Configure container DNS in user-defined networks (Engine)CouchDB (Engine)Create a base image (Engine)Create a swarm (Engine)Customize the docker0 bridge (Engine)Debian (Engine)Default bridge networkDelete the service (Engine)Deploy a service (Engine)Deploy services to a swarm (Engine)Deprecated Engine featuresDocker container networking (Engine)Docker overview (Engine)Docker run reference (Engine)Dockerfile reference (Engine)Dockerize an applicationDrain a node (Engine)EngineFAQ (Engine)Fedora (Engine)Get started (Engine)Get started with macvlan network driver (Engine)Get started with multi-host networking (Engine)How nodes work (Engine)How services work (Engine)Image management (Engine)Inspect the service (Engine)Install Docker (Engine)IPv6 with Docker (Engine)Join nodes to a swarm (Engine)Legacy container links (Engine)Lock your swarm (Engine)Manage nodes in a swarm (Engine)Manage sensitive data with Docker secrets (Engine)Manage swarm security with PKI (Engine)Manage swarm service networks (Engine)Migrate to Engine 1.10Optional Linux post-installation steps (Engine)Overview (Engine)PostgreSQL (Engine)Raft consensus in swarm mode (Engine)Riak (Engine)Run Docker Engine in swarm modeScale the service (Engine)SDKs (Engine)Select a storage driver (Engine)Set up for the tutorial (Engine)SSHd (Engine)Storage driver overview (Engine)Store service configuration data (Engine)Swarm administration guide (Engine)Swarm mode key concepts (Engine)Swarm mode overlay network security model (Engine)Swarm mode overview (Engine)Understand container communication (Engine)Use multi-stage builds (Engine)Use swarm mode routing mesh (Engine)Use the AUFS storage driver (Engine)Use the Btrfs storage driver (Engine)Use the Device mapper storage driver (Engine)Use the OverlayFS storage driver (Engine)Use the VFS storage driver (Engine)Use the ZFS storage driver (Engine)Engine: Admin GuideAmazon CloudWatch logs logging driver (Engine)Bind mounts (Engine)Collect Docker metrics with Prometheus (Engine)Configuring and running Docker (Engine)Configuring logging drivers (Engine)Control and configure Docker with systemd (Engine)ETW logging driver (Engine)Fluentd logging driver (Engine)Format command and log output (Engine)Google Cloud logging driver (Engine)Graylog Extended Format (GELF) logging driver (Engine)Journald logging driver (Engine)JSON File logging driver (Engine)Keep containers alive during daemon downtime (Engine)Limit a container's resources (Engine)Link via an ambassador container (Engine)Log tags for logging driver (Engine)Logentries logging driver (Engine)PowerShell DSC usage (Engine)Prune unused Docker objects (Engine)Run multiple services in a container (Engine)Runtime metrics (Engine)Splunk logging driver (Engine)Start containers automatically (Engine)Storage overview (Engine)Syslog logging driver (Engine)tmpfs mountsTroubleshoot volume problems (Engine)Use a logging driver plugin (Engine)Using Ansible (Engine)Using Chef (Engine)Using Puppet (Engine)View a container's logs (Engine)Volumes (Engine)Engine: CLIDaemon CLI reference (dockerd) (Engine)dockerdocker attachdocker builddocker checkpointdocker checkpoint createdocker checkpoint lsdocker checkpoint rmdocker commitdocker configdocker config createdocker config inspectdocker config lsdocker config rmdocker containerdocker container attachdocker container commitdocker container cpdocker container createdocker container diffdocker container execdocker container exportdocker container inspectdocker container killdocker container logsdocker container lsdocker container pausedocker container portdocker container prunedocker container renamedocker container restartdocker container rmdocker container rundocker container startdocker container statsdocker container stopdocker container topdocker container unpausedocker container updatedocker container waitdocker cpdocker createdocker deploydocker diffdocker eventsdocker execdocker exportdocker historydocker imagedocker image builddocker image historydocker image importdocker image inspectdocker image loaddocker image lsdocker image prunedocker image pulldocker image pushdocker image rmdocker image savedocker image tagdocker imagesdocker importdocker infodocker inspectdocker killdocker loaddocker logindocker logoutdocker logsdocker networkdocker network connectdocker network createdocker network disconnectdocker network inspectdocker network lsdocker network prunedocker network rmdocker nodedocker node demotedocker node inspectdocker node lsdocker node promotedocker node psdocker node rmdocker node updatedocker pausedocker plugindocker plugin createdocker plugin disabledocker plugin enabledocker plugin inspectdocker plugin installdocker plugin lsdocker plugin pushdocker plugin rmdocker plugin setdocker plugin upgradedocker portdocker psdocker pulldocker pushdocker renamedocker restartdocker rmdocker rmidocker rundocker savedocker searchdocker secretdocker secret createdocker secret inspectdocker secret lsdocker secret rmdocker servicedocker service createdocker service inspectdocker service logsdocker service lsdocker service psdocker service rmdocker service scaledocker service updatedocker stackdocker stack deploydocker stack lsdocker stack psdocker stack rmdocker stack servicesdocker startdocker statsdocker stopdocker swarmdocker swarm cadocker swarm initdocker swarm joindocker swarm join-tokendocker swarm leavedocker swarm unlockdocker swarm unlock-keydocker swarm updatedocker systemdocker system dfdocker system eventsdocker system infodocker system prunedocker tagdocker topdocker unpausedocker updatedocker versiondocker volumedocker volume createdocker volume inspectdocker volume lsdocker volume prunedocker volume rmdocker waitUse the Docker command line (Engine)Engine: ExtendAccess authorization plugin (Engine)Docker log driver pluginsDocker network driver plugins (Engine)Extending Engine with pluginsManaged plugin system (Engine)Plugin configuration (Engine)Plugins API (Engine)Volume plugins (Engine)Engine: SecurityAppArmor security profiles for Docker (Engine)Automation with content trust (Engine)Content trust in Docker (Engine)Delegations for content trust (Engine)Deploying Notary (Engine)Docker security (Engine)Docker security non-events (Engine)Isolate containers with a user namespace (Engine)Manage keys for content trust (Engine)Play in a content trust sandbox (Engine)Protect the Docker daemon socket (Engine)Seccomp security profiles for Docker (Engine)Secure EngineUse trusted imagesUsing certificates for repository client verification (Engine)Engine: TutorialsEngine tutorialsNetwork containers (Engine)Get StartedPart 1: OrientationPart 2: ContainersPart 3: ServicesPart 4: SwarmsPart 5: StacksPart 6: Deploy your appMachineAmazon Web Services (Machine)Digital Ocean (Machine)docker-machine activedocker-machine configdocker-machine createdocker-machine envdocker-machine helpdocker-machine inspectdocker-machine ipdocker-machine killdocker-machine lsdocker-machine provisiondocker-machine regenerate-certsdocker-machine restartdocker-machine rmdocker-machine scpdocker-machine sshdocker-machine startdocker-machine statusdocker-machine stopdocker-machine upgradedocker-machine urlDriver options and operating system defaults (Machine)Drivers overview (Machine)Exoscale (Machine)Generic (Machine)Get started with a local VM (Machine)Google Compute Engine (Machine)IBM Softlayer (Machine)Install MachineMachineMachine CLI overviewMachine command-line completionMachine concepts and helpMachine overviewMicrosoft Azure (Machine)Microsoft Hyper-V (Machine)Migrate from Boot2Docker to MachineOpenStack (Machine)Oracle VirtualBox (Machine)Provision AWS EC2 instances (Machine)Provision Digital Ocean Droplets (Machine)Provision hosts in the cloud (Machine)Rackspace (Machine)VMware Fusion (Machine)VMware vCloud Air (Machine)VMware vSphere (Machine)NotaryClient configuration (Notary)Common Server and signer configurations (Notary)Getting started with NotaryNotary changelogNotary configuration filesRunning a Notary serviceServer configuration (Notary)Signer configuration (Notary)Understand the service architecture (Notary)Use the Notary client
文字

  • 1:概况介绍

  • 2:集装箱

  • 3:服务

  • 4:成群

  • 5:堆叠

  • 6:部署应用程序

先决条件

  • 安装Docker版本1.13或更高版本。

  • 弄到码头组成如上文所述第三部分先决条件...

  • 弄到码头机械如上文所述第四部分先决条件...

  • 阅读第1部分中的方向。

  • 学习如何在第2部分中创建容器。

  • 确保您已经发布了friendlyhello你创造的形象将其推送到注册表.我们将在这里使用这个共享的图像。

  • 确保你的图像作为一个部署的容器。运行此命令,在您的信息开槽usernamerepotagdocker run -p 80:80 username/repo:tag,然后访问http://localhost/

  • 有一份你的docker-compose.yml从第3部分手巧。

  • 确保你安装的机器第4部分已经准备好了。跑docker-machine ls来验证这个。如果机器停止运行docker-machine start myvm1引导经理,然后是docker-machine start myvm2启动工人。

  • 让你创造的蜂群第4部分准备好了。跑docker-machine ssh myvm1 "docker node ls"来验证这个。如果群集出现,两个节点都将报告一个ready现状。如果没有,请重新初始化蜂群,并按照建立你的蜂群...导言在第4部分,您了解了如何设置一个群集,这是一个运行Docker的机器集群,并在其中部署了一个应用程序,容器在多台机器上协同运行。在第5部分中,您将到达分布式应用程序层次结构的顶端:堆叠堆栈是一组相互关联的服务,它们共享依赖关系,可以编排和缩放在一起。单个堆栈能够定义和协调整个应用程序%28的功能,尽管非常复杂的应用程序可能需要使用多个堆栈%29。一些好消息是,从技术上讲,从第3部分开始,您就一直在使用堆栈,那时您创建了一个撰写文件并使用了docker stack deploy但是,这是运行在单个主机上的单个服务堆栈,而这通常不是生产过程中发生的情况。在这里,您将学习到的知识,使多个服务相互关联,并运行在多台机器上。你做得很好,这是你的家添加新服务并重新部署将服务添加到我们的docker-compose.yml档案。首先,让我们添加一个免费的可视化服务,让我们看看我们的集群是如何调度容器的。

  • 敞开docker-compose.yml在编辑器中,并将其内容替换为以下内容。一定要更换username/repo:tag还有你的图像细节。

版本:“3”服务:web:#替换用户名/repo:标记与您的名称和图像详细信息图片:username/repo:标签部署:副本:5重新启动[医]策略:条件:失败资源:限制:cpu:“0.1”内存:50m端口:-“80:80”网络:-webnet可视化器:图像:dockersames/可视化器:稳定端口:-“8080:8080”卷:-“/var/run/docker.sock:/var/run/docker.sock”部署:放置:约束:node.ole==Manager网络:-网络网络:

这里唯一的新发现是对等服务web,命名visualizer.你会在这里看到两件新的事情:volumes键,使可视化器访问主机的Docker套接字文件,并且placement关键,确保该服务只在群集管理器上运行,而不是在员工身上运行。那是因为这个容器Docker创建的开源项目,显示在图表中的群集上运行的Docker服务。

稍后我们将更多地讨论位置限制和卷。

  1. 复制这个新的docker-compose.yml把文件交给蜂群经理,myvm1* 码头机scp码头-合成物.yml myvm 1:~

  1. 重新运行docker stack deploy命令,所有需要更新的服务都将被更新:

$ docker-machine ssh myvm1“docker stack deploy -c docker-compose.yml getstartedlab”更新服务getstartedlab_web(id:angi1bf5e4to03qu9f93trnxm)更新服务getstartedlab_visualizer(id:l9mnwkeq2jiononb5ihz9u7a4)

  1. 看看可视化器。您visualizer在端口8080 上运行的Compose文件中看到。通过运行获取其中一个节点的IP地址docker-machine ls。转到8080端口的IP地址,您将看到可视化器正在运行:您希望管理器上运行

的单个副本visualizer,并且5个实例web遍布整个群集。您可以通过运行来验证此可视化效果docker stack ps <stack>:docker-machine ssh myvm1“docker stack ps getstartedlab”可视化器是一个独立的服务,可以在任何包含它的应用程序中运行。它不依赖于其他任何东西。现在让我们创建一个服务 有一个依赖项:Redis服务将提供一个访问者counter.Persist dataLet再次通过相同的工作流程来添加一个Redis数据库来存储应用程序数据。

  1. 保存这个新的docker-compose.yml文件,它最终添加了Redis服务。一定要更换username/repo:tag还有你的图像细节。

版本:“3”服务:web:#替换用户名/repo:标记与您的名称和图像详细信息图片:username/repo:标签部署:副本:5重新启动[医]策略:条件:失败资源:限制:cpu:“0.1”内存:50m端口:-“80:80”网络:-webnet可视化器:图像:dockersames/可视化器:稳定端口:-“8080:8080”卷:-“/var/run/docker.sock:/var/run/docker.sock”部署:放置:约束:node.ole==Manager网络:-webnetredis:映像:redis端口:-“6379:6379”卷:-/data:/data部署:放置:约束:node.ole==Manager网络:-网络网络:

Redis在Docker图书馆有一个官方形象,并已被授予短图片。image名称...redis所以不username/repo这里的记号。Redis端口6379已经由Redis预先配置,以便从容器公开到主机,在我们的撰写文件中,我们将它从主机公开给全世界。因此,如果您愿意,您可以将任何节点的IP输入到RedisDesktopManager中,并管理这个Redis实例。

最重要的是,在redis使数据在此堆栈的部署之间保持不变的规范:

-  `redis` always runs on the manager, so it’s always using the same filesystem.-  `redis` accesses an arbitrary directory in the host’s file system as `/data` inside the container, which is where Redis stores data.

这将在主机的物理文件系统中为Redis数据创建一个“真相源”。没有这个,Redis就会将其数据存储在/data在容器的文件系统中,如果重新部署容器,它就会被清除掉。

这一真相来源有两个组成部分:

- The placement constraint you put on the Redis service, ensuring that it always uses the same host.- The volume you created that lets the container access `./data` (on the host) as `/data` (inside the Redis container). While containers come and go, the files stored on `./data` on the specified host will persist, enabling continuity.

您已经准备好部署新的Redis使用堆栈。

  1. 创建一个./data管理器上的目录: $docker-机器ssh myvm 1“mkdir./data”

  1. 复制新的docker-compose.ymldocker-machine scp*

$docker-机器SCP码头-Compose.yml myvm 1:~

  1. docker stack deploy再来一次。 $docker-Machine ssh myvm 1“坞库部署-c停靠库-come.yml getstartedlab”

  1. 检查您的节点之一的网页%28例如。http://192.168.99.101%29,您将看到访问者计数器的结果,该计数器现在是实时的,并在Redis上存储信息。

另外,检查节点的IP地址上端口8080处的可视化器,您将看到rediswebvisualizer服务。

关于第6部分

概述(可选)

这是本页所涵盖内容的终端记录*

您了解到堆栈是相互关联的服务,所有这些服务都是协同运行的,而自本教程第三部分以来,您就一直使用堆栈。您了解到要向堆栈中添加更多服务,请将它们插入撰写文件中。最后,您了解到,通过使用位置约束和卷的组合,您可以为持久化数据创建一个永久的主页,这样当容器被拆卸和重新部署时,应用程序的数据就能存活下来。

上一篇:下一篇: