I'm trying to create multiple containers in parallel and network them so they can reach each other. It is a cyclic dependency so Services currently cannot be used.
I am chaining together some .WithExec commands to log the IP address of each machine to a shared file on a cache mount. This is the discovery workaround.
container = container.WithExec([]string{"bash", "-c", "ip route get 1 | ip route get 1 | awk '{print $7}' | xargs >> /shared/peers"})
container = container.WithExec([]string{"bash", "-c", "while [ $(wc -l < /shared/peers) -lt 2 ]; do sleep .5 ; echo waiting for peers to log IP; done"})
container = container.WithExec([]string{"bash", "-c", "echo peers have IP addresses $(cat /shared/peers | paste -sd ',' -)"})
// ..
// later start the services
for _, s := range export {
go func() {
s.Start(ctx)
}()
}
However it seems that the IP addresses that get logged are not stable. It seems in subsequent .WithExec commands, the IP addresses logged beforehand are no longer valid, or that the IP address changed, or that the IP address is the same for both containers.
How can I start containers/services with stable IP addresses?
https://dagger.cloud/cordialsys/traces/7e4b6c1e8ccde4ec50285466ee18a709#970891ce5eb413d5
in this example they came out with the same IP:
https://dagger.cloud/cordialsys/traces/7e4b6c1e8ccde4ec50285466ee18a709?span=73addf0226a7d911
another run, same code, they ended up with different IPs:
https://dagger.cloud/cordialsys/traces/38308549de6d03230a5d7c45d83dcf2b?span=71163e2c220c83ae