Serie Docker: Episodio 24 — Docker Compose y Swarm: Despliegues multi-host

Guía práctica: combina Docker Compose y Swarm para despliegues multi-host. Define servicios, redes y secretos, escala y actualiza con Docker Stack y mejores prácticas.

15 sept 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Bienvenido de nuevo a la serie Docker: Episodio 24 — Docker Compose y Swarm: Despliegues multi-host. En este artículo explicamos cómo combinar la simplicidad de Docker Compose con la orquestación de Docker Swarm para desplegar aplicaciones multi-contenedor a través de varios hosts, y cómo Q2BSTUDIO puede ayudarte a implementar soluciones a medida, robustas y seguras.

Por qué integrar Compose con Swarm: Compose facilita la definición de servicios, redes y volúmenes en formato declarativo, mientras que Swarm aporta orquestación, escalado automático, alta disponibilidad y tolerancia a fallos. La combinación permite desplegar aplicaciones complejas en clusters sin perder la legibilidad de la configuración.

Preparando Compose para Swarm: Docker Compose v3 y superiores son compatibles con el modo Swarm. Define servicios, redes y volúmenes como de costumbre y agrega la sección deploy para parámetros específicos de Swarm. Ejemplo resumido de una configuración típica: version: 3.8 services web: image nginx:latest ports 80:80 deploy replicas 3 update_config parallelism 1 delay 10s restart_policy condition on-failure

Despliegue en Swarm: utiliza el comando docker stack deploy -c docker-compose.yml mystack para desplegar una pila definida con Compose en modo Swarm. Docker interpreta el archivo Compose y crea servicios Swarm basados en esas definiciones. Para comprobar el estado usa docker stack services mystack y para ver tareas usa docker service ls seguido de docker service ps nombre_servicio.

Escalado y actualizaciones: puedes escalar un servicio con docker service scale mystack_web=5. Para actualizaciones continuas edita la imagen en el archivo docker-compose.yml y vuelve a ejecutar docker stack deploy -c docker-compose.yml mystack para aplicar rolling updates según la política definida en deploy update_config.

Red y secretos: las redes overlay declaradas en Compose se crean automáticamente en los nodos del Swarm, permitiendo comunicación multi-host. Secrets y configs también pueden definirse en Compose, ejemplo sintético: secrets db_password: file ./db_password.txt services db: image postgres:latest secrets - db_password. Gestionar secretos con Compose facilita integrarlos en despliegues seguros y auditable.

Buenas prácticas: usa Compose v3 o superior para compatibilidad con Swarm. Define replicas, update_config y restart_policy bajo deploy. Emplea redes overlay para comunicación entre hosts y gestiona secretos y configs desde Compose. Prueba en un pequeño cluster Swarm antes de pasar a producción y monitorea métricas y logs para detectar regresiones.

Retos prácticos: crea una app Compose multi-contenedor con web, db y cache. Añade parámetros deploy como replicas y update_config. Despliega con docker stack deploy en varios nodos. Comprueba escalado, actualizaciones rolling y uso de secretos. Esta práctica es ideal para validar despliegues antes de una migración a producción.

Sobre Q2BSTUDIO: somos una empresa de desarrollo de software que ofrece aplicaciones a medida, software a medida y servicios de inteligencia artificial para empresas. Como especialistas en ciberseguridad, podemos auditar y proteger tus despliegues Docker y plataformas cloud. Si necesitas desarrollar una aplicación enterprise o migrar a la nube, consulta nuestras soluciones de desarrollo de aplicaciones en aplicaciones a medida y software a medida y nuestros servicios gestionados en Servicios cloud AWS y Azure.

Palabras clave: aplicaciones a medida, software a medida, inteligencia artificial, ciberseguridad, servicios cloud aws y azure, servicios inteligencia de negocio, ia para empresas, agentes IA, power bi. Estas áreas complementan la infraestructura de contenedores y orquestación para ofrecer soluciones integrales y seguras en producción.

Próximo episodio: episodio 25 — Docker Troubleshooting y Debugging: problemas comunes y soluciones, donde aprenderás a identificar y resolver incidencias reales en entornos de contenedores de forma ágil y eficaz.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat