Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

414
Vistas
Docker-Compose Restart Policy

I looked thru the docs for docker-compose and I see that Version 3 has a deploy restart policy but it's only for swarm. I tried setting restart_policy on my service but got this error:

ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.web: 'restart_policy'

Is there any way to set a restart policy on services created using docker-compose outside of a swarm?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

It looks like a gap in the documentation

In 3rd version, we can still use "restart" inside services same as before in v.2 (except for deploy into swarm)

version: '3'
services:
  my-service:
    restart: on-failure:5 

https://docs.docker.com/compose/compose-file/compose-file-v3/#restart_policy

over 4 years ago · Santiago Trujillo Denunciar

0

Version 2 supports restart policies, using the restart keyword, and should work fine for you if you don't need Swarm (which you said you don't need/want).

version: '2'
services:
  web:
    image: apache
    restart: always

https://docs.docker.com/compose/compose-file/compose-file-v2/#restart

Compose format version 3 has a parameter called restart_policy, but so far as I can tell from documentation it is only valid as part of deploy, which is only used when deploying to a Swarm. So version 3 is probably not useful in your case.

over 4 years ago · Santiago Trujillo Denunciar

0

Even if you're NOT in swarm mode, there is an option called --compatibility which will work with restart_policy, this will attempt to restart even if you're not deploying. The only glitch, is the sub-keys of 'delay' and 'window' will be ignored. Here is an example:

version: '3.7'
services:
  build:
    context: .
    dockerfile: Dockerfile
  container_name: example
  deploy:
    restart_policy:
      condition: on-failure
      max-attempts: 3

run this command:

docker-compose -f docker-compose.yml --compatability up
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda