1

Given the limitations of the Terraform Docker Provider (see Terraform Docker Provider: "Bind" port to specific network), is there a way to execute a command ON the Docker host AFTER a Container has been started?

Since you can't specify what Docker Network to attach specific ports{} blocks to, maybe I can start my CNF with just one network defined so Terraform will bind the ports to that network, then add the other networks to the Container after that and start or restart it? My Docker host is remote, otherwise I would have just been using a shell script to start things correctly without the Terraform limitations.

JD Allen
  • 799
  • 5
  • 12
  • There's always the ["null_resource" resource](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource), if you have some other path to connect to the remote host. – David Maze Sep 16 '20 at 18:47
  • @DavidMaze: Can you define "some other path"? I can always SSH into the Docker host and do a manual process, but that kind of defeats the whole point of using Terrafom. – JD Allen Sep 16 '20 at 18:52
  • Right, you can use a `null_resource` to trigger a provisioner separately from the normal Terraform resource flow, and that can run arbitrary commands over ssh. But it is kind of an escape hatch. (My loose experience has been that Terraform is great for things like getting cloud instances, and not so great for managing the software on them.) – David Maze Sep 16 '20 at 22:13

0 Answers0