dockerazure-iot-edgedocker-engine

Is there a way to enforce inter-module dependencies/initialization order?


Using Azure IoT Edge, I have not found any way to guarantee the initialization order of containers/modules in a deployment. Suppose for example, I have 2 modules, A and B. A is a server and B is a client that depends on A. As far as I know, there's no way to guarantee that A starts up before B does.

The Azure IoT Edge deployment templates conform to the Docker Engine API, and I could not find any way to enforce dependencies through that API. As a workaround, I make no assumptions about which containers are running in each container's code. This works, although the overhead of additional code is not ideal, especially considering a tool like docker-compose would make enforcing initialization order rather trivial.

I want to do something like this (src: https://docs.docker.com/compose/compose-file/):

version: "3.7"
services:
  web:
    build: .
    depends_on:
      - db
      - redis
  redis:
    image: redis
  db:
    image: postgres

As a workaround, and following the example above, in the web container I've been doing things like the following to ensure postgres is up and running before web performs postgres dependent actions:

postgresIsUp = False
while not postgresIsUp:
    try:
        pingPostgres()
        postgresIsUp = True
    except PingError:
        print("postgres is not yet running")

This is, of course, a contrived example with obvious flaws, but it demonstrates the gist of the workaround.


Solution

  • StartupOrder: Introduced in IoT Edge version 1.0.10. Which order the IoT Edge agent should start the modules when first deployed.