Deploying Services to Swarm
Deploy and scale containerized applications as services on your Swarm cluster, managing their lifecycle.
Deploying Services to Swarm is a free Docker & DevOps Fundamentals lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Docker & DevOps Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What is a Docker Swarm Service?
In Docker Swarm, a service is the definition of how you want to run a containerized application across your cluster.
Instead of running individual containers, you define a service to tell Swarm: "I want to run X instances of this image, on these ports, with these settings."
Swarm then ensures your desired state is maintained, automatically restarting containers if they fail.

Services vs. Containers
Think of it this way:
- A container is a single instance of an application.
- A service is a blueprint for running one or more identical containers (called tasks) across your Swarm.
Services provide high availability and scalability by distributing tasks and handling failures automatically.
Deploying Your First Service
The docker service create command is how you deploy applications as services to your Swarm cluster. Let's create a simple Nginx web server service.
Try running this example:
docker service create \
--name my-web-app \
-p 80:80 \
--replicas 1 \
nginxUnderstanding Service Creation
Let's break down the command we just used:
--name my-web-app: Gives your service a memorable name.-p 80:80: Maps port 80 on the Swarm nodes to port 80 inside the container.--replicas 1: Tells Swarm to maintain one running instance (task) of this service.nginx: Specifies the Docker image to use for the service's tasks.
Inspecting Your Services
After creating a service, you'll want to verify its status and see its running tasks. Use these commands:
docker service ls: Lists all services in your Swarm.docker service ps <service_name>: Shows the individual tasks (containers) associated with a service.
docker service ls
docker service ps my-web-appScaling Up Your Service
One of the core benefits of Docker Swarm is easy scaling. You can increase the number of running instances (replicas) of your service with a single command.
Let's scale our my-web-app to three replicas:
docker service scale my-web-app=3Scaling Down Your Service
Just as easily, you can scale down your service to reduce resource usage or manage traffic. Swarm will gracefully stop the excess containers while keeping the remaining ones running.
Let's scale my-web-app back down to one replica:
docker service scale my-web-app=1Updating a Service
When you need to deploy a new version of your application or change service settings, docker service update performs a rolling update. Swarm updates tasks one by one, ensuring your application remains available.
Let's update our Nginx service to a specific version:
docker service update --image nginx:1.25 my-web-appRemoving a Service
When a service is no longer needed, you can remove it from your Swarm. This will stop all associated tasks and delete the service definition from the cluster.
To remove our example web app service:
docker service rm my-web-appService Management Quiz
You have a service named my-backend running with 3 replicas and using the image my-backend:v1. You need to update it to use a new image, my-backend:v2, and also increase its replicas to 5.
Recap: Swarm Services
Great job! You've learned the essentials of deploying and managing applications as services in Docker Swarm.
- Services define the desired state for your containerized apps.
- You learned to create services using
docker service create. - We covered inspecting, scaling (
docker service scale), and updating (docker service update) services. - Finally, you can remove services with
docker service rm.
Services are fundamental for building scalable and resilient applications in a Swarm cluster!
Frequently asked questions
Is the “Deploying Services to Swarm” lesson free?
Yes — the full text of “Deploying Services to Swarm” is free to read here on the web, and the Docker & DevOps Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Docker & DevOps Fundamentals course, upgrade to CoddyKit PRO.
What will I learn in “Deploying Services to Swarm”?
Deploy and scale containerized applications as services on your Swarm cluster, managing their lifecycle. You practise Docker & DevOps Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Docker & DevOps Fundamentals?
No prior experience is required. Docker & DevOps Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Deploying Services to Swarm” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Docker & DevOps Fundamentals lesson?
Yes. Every Docker & DevOps Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Introduction to Docker Swarm
- Setting Up a Swarm Cluster
- Deploying Services to Swarm
- Scaling and Rolling Updates in Swarm