Home > Mobile >  Difference in restart and restart_policy in docker_compose.yml
Difference in restart and restart_policy in docker_compose.yml

Time:11-05

I have a docker-compose file for some services, among them an airflow-webserver. I realized that I can both add restart and deploy-restart_policy to the compose file. I tried searching for a difference between the two, but could only find posts discussing the individual settings (like on-failure or always).

  • What is the difference of setting the configuration?
  • Which should I use?
  • Is it a versioning issue, e.g. restart is from older versions and deploy-restart_policy is the newer one?

Example docker-compose.yml:

version: "3"
services:
  airflow-webserver:
    container_name: airflow_container
    image: puckel/docker-airflow
    ports:
      - '8080:8080'
    networks:
      - dataworld
    volumes:
      - ./airflow/dags:/usr/local/airflow/dags
      - ./airflow/logs:/usr/local/airflow/logs
    deploy:
      restart_policy:
        condition: on-failure
    restart: on-failure

CodePudding user response:

The restart and deploy.restart_policy options configure the same thing but depend on the way you run your containers:

  • restart is used by Docker Compose
  • deploy.restart_policy is used by Docker Swarm

The deploy option is used for Docker Swarm only and is ignored by Docker Compose.

From the documentation on deploy.restart_policy:

Configures if and how to restart containers when they exit. Replaces restart.

And here about restart:

The restart option is ignored when deploying a stack in swarm mode.

  • Related