Docker compose yml static IP addressing

In my case is i first run docker-compose up failed, but the network already created, can see using docker network ls.

In this case, just docker-compose down, fix the yml, rerun docker-compose up is fine


[SOLVED] Found the solution. When pointing to the network, we should use flag "external" telling compose that network is already created and should be taken outside (otherwise it will be created on the fly with project prefix):

networks:
  app_subnet:
    external: true

So, after that docker-compose will attach containers to existing app_subnet Before that the subnet must be created:

docker network create --gateway 172.16.1.1 --subnet 172.16.1.0/24 app_subnet