目錄 搜尋
Compose About 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 bundle docker-compose config docker-compose create docker-compose down docker-compose events docker-compose exec docker-compose help docker-compose images docker-compose kill docker-compose logs docker-compose pause docker-compose port docker-compose ps docker-compose pull docker-compose push docker-compose restart docker-compose rm docker-compose run docker-compose scale docker-compose start docker-compose stop docker-compose top docker-compose unpause docker-compose up Environment file (Compose) Environment variables in Compose Extend services in Compose Frequently asked questions (Compose) Getting started (Compose) Install Compose Link environment variables (deprecated) (Compose) Networking in Compose Overview of Docker Compose Overview of docker-compose CLI Quickstart: Compose and WordPress Rails and PostgreSQL (Compose) Sample apps with Compose Using Compose in production Using Compose with Swarm Engine .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-ng Best 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 network Delete the service (Engine) Deploy a service (Engine) Deploy services to a swarm (Engine) Deprecated Engine features Docker container networking (Engine) Docker overview (Engine) Docker run reference (Engine) Dockerfile reference (Engine) Dockerize an application Drain a node (Engine) Engine FAQ (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.10 Optional Linux post-installation steps (Engine) Overview (Engine) PostgreSQL (Engine) Raft consensus in swarm mode (Engine) Riak (Engine) Run Docker Engine in swarm mode Scale 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 Guide Amazon 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 mounts Troubleshoot 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: CLI Daemon CLI reference (dockerd) (Engine) docker docker attach docker build docker checkpoint docker checkpoint create docker checkpoint ls docker checkpoint rm docker commit docker config docker config create docker config inspect docker config ls docker config rm docker container docker container attach docker container commit docker container cp docker container create docker container diff docker container exec docker container export docker container inspect docker container kill docker container logs docker container ls docker container pause docker container port docker container prune docker container rename docker container restart docker container rm docker container run docker container start docker container stats docker container stop docker container top docker container unpause docker container update docker container wait docker cp docker create docker deploy docker diff docker events docker exec docker export docker history docker image docker image build docker image history docker image import docker image inspect docker image load docker image ls docker image prune docker image pull docker image push docker image rm docker image save docker image tag docker images docker import docker info docker inspect docker kill docker load docker login docker logout docker logs docker network docker network connect docker network create docker network disconnect docker network inspect docker network ls docker network prune docker network rm docker node docker node demote docker node inspect docker node ls docker node promote docker node ps docker node rm docker node update docker pause docker plugin docker plugin create docker plugin disable docker plugin enable docker plugin inspect docker plugin install docker plugin ls docker plugin push docker plugin rm docker plugin set docker plugin upgrade docker port docker ps docker pull docker push docker rename docker restart docker rm docker rmi docker run docker save docker search docker secret docker secret create docker secret inspect docker secret ls docker secret rm docker service docker service create docker service inspect docker service logs docker service ls docker service ps docker service rm docker service scale docker service update docker stack docker stack deploy docker stack ls docker stack ps docker stack rm docker stack services docker start docker stats docker stop docker swarm docker swarm ca docker swarm init docker swarm join docker swarm join-token docker swarm leave docker swarm unlock docker swarm unlock-key docker swarm update docker system docker system df docker system events docker system info docker system prune docker tag docker top docker unpause docker update docker version docker volume docker volume create docker volume inspect docker volume ls docker volume prune docker volume rm docker wait Use the Docker command line (Engine) Engine: Extend Access authorization plugin (Engine) Docker log driver plugins Docker network driver plugins (Engine) Extending Engine with plugins Managed plugin system (Engine) Plugin configuration (Engine) Plugins API (Engine) Volume plugins (Engine) Engine: Security AppArmor 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 Engine Use trusted images Using certificates for repository client verification (Engine) Engine: Tutorials Engine tutorials Network containers (Engine) Get Started Part 1: Orientation Part 2: Containers Part 3: Services Part 4: Swarms Part 5: Stacks Part 6: Deploy your app Machine Amazon Web Services (Machine) Digital Ocean (Machine) docker-machine active docker-machine config docker-machine create docker-machine env docker-machine help docker-machine inspect docker-machine ip docker-machine kill docker-machine ls docker-machine provision docker-machine regenerate-certs docker-machine restart docker-machine rm docker-machine scp docker-machine ssh docker-machine start docker-machine status docker-machine stop docker-machine upgrade docker-machine url Driver 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 Machine Machine Machine CLI overview Machine command-line completion Machine concepts and help Machine overview Microsoft Azure (Machine) Microsoft Hyper-V (Machine) Migrate from Boot2Docker to Machine OpenStack (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) Notary Client configuration (Notary) Common Server and signer configurations (Notary) Getting started with Notary Notary changelog Notary configuration files Running a Notary service Server 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部分

概述(可选)

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

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

上一篇: 下一篇: