terraform-provider-docker icon indicating copy to clipboard operation
terraform-provider-docker copied to clipboard

Support for Docker exec

Open airmoi opened this issue 2 years ago • 1 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Provisioning sometimes requires to run extra commands in a container using docker exec... For now we have to use null_ressource local/remote-exec to run "docker exec" commands which is not very handy as we always need to add all the "docker exec" stuff, pass the container name and so on... Would by great to add something like :

resource "docker_exec" "custom_commands" {
    container = docker_container.my_container.id
    trigger= ..
    count= ...
    command = "<any custom commands here>"
}

New or Affected Resource(s)

  • docker_exec

Potential Terraform Configuration

resource "docker_container" "ftp" {
  image = some-ftp-image
  name  = my-ftp
  ...
}
resource "docker_exec" "custom_commands" {
    container = docker_container.my_container.id
    command = <<EOT
useradd ${var.ftp_user} ...
echo "Hello ${var.ftp_user}" > "/home/${var.ftp_user}/README.txt"
EOT
}

airmoi avatar Mar 29 '23 15:03 airmoi

I think this resource would be in violation of the concept of terraform. Communicating with the container via a special resource seems not to be in scope of the docker provider.

In your case, instead of adding the user via docker exec, you could have added it also at startup script or even inside the image build.

I get that not having to shut the container down for adding a user is a use case, however trying to trigger this mechanism via some terraform resources seems to be a bad choice.

domoran avatar Jan 06 '24 21:01 domoran

This would be an ideal case to implement the new actions type (https://developer.hashicorp.com/terraform/plugin/framework/actions) To implement this,, however, we need to migration to the new provider framework first.

Junkern avatar Oct 30 '25 22:10 Junkern