Home Explore Blog CI



docker

2nd chunk of `content/guides/swarm-deploy.md`
9695bfafefb1b7c1f16fb8f87212a8ce01e2f6c458bafa6d000000010000091e
Swarm never creates individual containers like you did in the previous step of this tutorial. Instead, all Swarm workloads are scheduled as services, which are scalable groups of containers with added networking features maintained automatically by Swarm. Furthermore, all Swarm objects can and should be described in manifests called stack files. These YAML files describe all the components and configurations of your Swarm app, and can be used to create and destroy your app in any Swarm environment.

Now you can write a simple stack file to run and manage your Todo app, the container `getting-started` image created in [Part 2](02_our_app.md) of the tutorial. Place the following in a file called `bb-stack.yaml`:

{{% include "swarm-compose-compat.md" %}}

```yaml
version: "3.7"

services:
  bb-app:
    image: getting-started
    ports:
      - "8000:3000"
```

In this Swarm YAML file, there is one object, a `service`, describing a scalable group of identical containers. In this case, you'll get just one container (the default), and that container will be based on your `getting-started` image created in [Part 2](02_our_app.md) of the tutorial. In addition, you've asked Swarm to forward all traffic arriving at port 8000 on your development machine to port 3000 inside our getting-started container.

> **Kubernetes Services and Swarm Services are very different**
>
> Despite the similar name, the two orchestrators mean very different things by
> the term 'service'. In Swarm, a service provides both scheduling and
> networking facilities, creating containers and providing tools for routing
> traffic to them. In Kubernetes, scheduling and networking are handled
> separately, deployments (or other controllers) handle the scheduling of
> containers as pods, while services are responsible only for adding
> networking features to those pods.

## Deploy and check your application

1. Deploy your application to Swarm:

   ```console
   $ docker stack deploy -c bb-stack.yaml demo
   ```

   If all goes well, Swarm will report creating all your stack objects with no complaints:

   ```shell
   Creating network demo_default
   Creating service demo_bb-app
   ```

   Notice that in addition to your service, Swarm also creates a Docker network by default to isolate the containers deployed as part of your stack.

Title: Deploying and Verifying the Application on Docker Swarm
Summary
This section explains how to deploy an application to Docker Swarm using a stack file (bb-stack.yaml). It highlights that Swarm schedules workloads as services (scalable groups of containers) rather than individual containers. The provided YAML file defines a service for a Todo app, specifying the image to use and port forwarding. The 'docker stack deploy' command deploys the application, creating both the service and a default Docker network. A note clarifies the difference between Kubernetes Services and Swarm Services.