Using Docker Compose, how do you define that a service should be restarted after a failure?
Experience Level: Senior
Tags: Docker Compose
Answer
Add the restart: property to your service definition:
version: "3.9"
services:
web:
image: mysql:5.7
restarts: always
Related Docker Compose job interview questions
How does Docker Compose work with multiple .yml files?
Docker Compose SeniorHow do you pull all images associated with services defined in your docker-compose.yml file?
Docker Compose SeniorUsing Docker Compose, how do you define that one service is dependent on another service?
Docker Compose SeniorHow do you use definitions that are stored in multiple Docker Compose files?
Docker Compose JuniorHow do you mount a volume to your Docker Compose service?
Docker Compose Junior