vsupalov

What Exactly is Docker Swarm?

A short overview of the most important changes.

[ docker ]

Docker version 1.12 Swarm mode was integrated with Docker Engine but what is it exactly and how can you use it? Should you care?

If You’re A Ubuntu Users

The most recent version of the Docker Engine, is available as a “community edition”, older package versions were called docker-engine or just docker.

If you’re on Ubuntu and have been using the docker-engine package before, you probably want to upgrade

Swarm Mode

A swarm is a cluster of one or more computers running Docker. It can consist of one or more machines, so you can use swarm functionality on your local machine.

With the introduction of swarm mode, Docker received built-in orchestration, clustering and scheduling capabilities. Features for handling multiple machines, like health checks, load balancing and a bunch of other nice things are now included out-of-the-box.

Two services which were previously external additions, working on top of the Docker engine got included natively - Swarm and Docker Compose. But they’re not just packaged with it.

Unlike with the legacy standalone Swarm, the functionality is now built into the Docker engine itself. It was a separate service, not part of the docker daemon and interacted with the Docker API (just like Kubernetes and friends still do. You can read more about the concepts here and get started with this tutorial With swarm mode enabled and a docker-compose.yml file which is written according to the version 3 specification you can issue docker stack commands which bring up stacks of services.

When you run containers with the Docker command, swarm mode does not come into play by default. If you are using swarm mode, you are dealing on a higher abstraction level - services instead of containers. You can deal with both kinds on the same machine.

When a container is running in service mode, swarm mode takes over and manages the lifecycle of the service. It strives to bring up a desired number of replicas, as specified in the definition. That part of the funcionality is very similar to Kubernetes.

But I Don’t Run a Cluster

So, you don’t happen to be interested in running multiple computers, and have Docker take care of orchestrating stuff. In fact, you only have a single server with your current projects and are developing locally using docker-compose. What’s in it for you?

Kick your docker engine into being a one-machine-swarm mode with docker swarm init. Now, you can use docker stack commands.

Conclusion

Docker Swarm is something to orchestrate clusters, but it also got some functionality which was prior to docker compose into the docker engine itself. In addition, the packaging changed - you can get the new version for Ubuntu here.

With the stack command, the Docker engine takes care of bringing up stacks of containers using docker stack deploy, which was taken care of by docker-compose previously.

Master Docker ARG and ENV in 5 Days

Sign up to the free 5-day email course, and learn all you need to know about using environment and build-time variables with Docker. Get actionable advice, best practices and nifty tricks to use for your next project.