skip to Main Content

I have compose.yml file:

  api:
    restart: on-failure
    command: uvicorn app:app
    ...

  jobs:
    restart: on-failure
    command: python job.py
    ...

job.py:

import asyncio
from prometheus_client import start_http_server

async def background(sio):
    await asyncio.gather(...) # <- there are many tasks with while True


start_http_server(5000)
asyncio.run(background(sio))

It works okay. After stopping everything turns off. But when I restart system, jobs container starting automatically. Why?! api is not starting, but why jobs starting?

2

Answers


  1. I think Docker is just trying to run the containers that were running before the system shutdown. Maybe try to change restart policy to no to prevent restarting on startup?

      jobs:
        restart: no
    
    Login or Signup to reply.
  2. According to the documentation unless-stopped is probably the right option.

      jobs:
        restart: unless-stopped
        command: python job.py
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search