111763 Views
85221 Views
83639 Views
51774 Views
49949 Views
48472 Views
Obsidian - the best tool for Makers
10 Projects for your Raspberry Pi Pico
Raspberry Pi Telegraf Setup with Docker
Setting Up Dynamic DNS on a Raspberry Pi for Self-Hosting
Raspberry Pi WordPress Setup with Docker
Raspberry Pi WireGuard VPN Setup with Docker
Using the Raspberry Pi Pico's Built-in Temperature Sensor
Getting Started with SQL
Introduction to the Linux Command Line on Raspberry Pi OS
How to install MicroPython
Wall Drawing Robot Tutorial
BrachioGraph Tutorial
KevsRobots Learning Platform
42% Percent Complete
By Kevin McAleer, 5 Minutes
Deploying applications on a Docker Swarm cluster requires understanding the tools available for managing service configurations and orchestrations. This lesson introduces Docker Compose and Swarm Stacks, explaining their purposes, differences, and how to use them effectively in a Swarm environment.
Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services, networks, and volumes. Then, with a single command, you create and start all the services defined in your configuration.
Swarm Stacks are similar to Docker Compose but are specifically designed for managing applications across a Docker Swarm cluster. Stacks allow you to deploy, update, and scale services across multiple Docker hosts within the Swarm.
docker-compose up
docker stack deploy
docker-compose.yml
Deploy the Stack:
Run the following command on a manager node to deploy the stack:
docker stack deploy -c docker-compose.yml <STACK_NAME>
Replace <STACK_NAME> with a name for your stack.
<STACK_NAME>
Check the status of your stack with:
docker stack services <STACK_NAME>
This command lists the services in your stack, along with their replicas and status.
You may often need to update docker services with the latest version of a container. One of quirks of docker is that it does not automatically update the containers to the latest version, when you do docker service update <SERVICENAME>. You need to follow the process below, in this example a service called kevsrobots is updated to the latest version.
docker service update <SERVICENAME>
kevsrobots
Build (or Rebuild) and tag the image
docker build -t 192.168.2.1:5000/kevsrobots:latest .
Push the image After rebuilding your image, tag it (even if you’re reusing the latest tag) and push it to the registry.
docker push 192.168.2.1:5000/kevsrobots:latest
Update the Service To update the service and force all nodes to pull the latest image, use the –image flag with the docker service update command, specifying the full image name, including the tag:
docker service update --image 192.168.2.1:5000/kevsrobots:latest kevsrobots
Force Pull: If you want to explicitly ensure that Docker Swarm pulls the image on each node, you can use the –with-registry-auth flag to pass registry authentication credentials to the Swarm nodes. This is particularly useful if your image is stored in a private registry that requires authentication.
docker service update --image 192.168.2.1:5000/kevsrobots:latest --with-registry-auth kevsrobots
No Downtime: Ensure you have configured the service with an appropriate update policy to achieve zero downtime deployments. You can set parameters like –update-parallelism and –update-delay to control the rollout of the update across the service’s tasks.
docker service update --image 192.168.2.1:5000/kevsrobots:latest --update-parallelism 1 --update-delay 10s kevsrobots
Rollback Strategy: It’s also a good practice to configure a rollback strategy in case the new version of the image introduces issues.
docker service update --image 192.168.2.1:5000/kevsrobots:latest --rollback-parallelism 1 --rollback-delay 10s kevsrobots
By following these steps, you can ensure that all nodes in your Docker Swarm pull and use the latest version of your image, maintaining the consistency of your deployment.
Docker Compose and Swarm Stacks provide powerful and flexible tools for deploying and managing containerized applications. Understanding when and how to use each tool is crucial for effectively managing your Docker Swarm cluster. By leveraging Docker Stacks, you can take full advantage of Docker Swarm’s capabilities for deploying scalable and resilient applications across multiple nodes in your cluster.
< Previous Next >