Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
why container api launching after the container containing my script

I have a docker compose launching 2 containers. Problem is that it seems that my container with the api that I need to reach from the other container start only after and then I have a request issue.

version: "3.9"
services:
  fastapi:
    container_name: my-api
    image: fastapi:latest
    networks:
      - my-network
    ports: 
      - target: 8000
        published: 8000
        mode: host
  authentification:
    container_name: authentification
    networks:
      - my-network
    image: authentification:latest
    volumes:
      - .:/home/log_folder
    depends_on:
      - "fastapi"

networks:
  my-network:

Th containers can communicate together as If I launch manually the container with the script authentification after the api is started, it works.

Any clue ?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I finally added a time.sleep at he beginning of each of my container with script reaching the api to ensure they wait the api is launched. This is not a big issue as these scripts are just test script to check authentification etc ...

Thanks !

over 4 years ago · Santiago Trujillo Report

0

Dependency checks only container startup, not service. time.sleep is a crutch, actually. Just add healthcheck block to your fastapi service

fastapi:
  healthcheck:
    test: ["CMD", "curl", "-f", "http://localhost:8000"]
    interval: 1s
    timeout: 2s
    retries: 10

and change dependency block to this:

authentification:
  depends_on:
    fastapi:
      condition: service_healthy
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!