--- # generated by https://github.com/hashicorp/terraform-plugin-docs page_title: "docker_exec Action - terraform-provider-docker" subcategory: "" description: |- Run a command in an existing container, similar to docker container exec. Please note that due to the nature of actions, we cannot have an computed output attribute that contains the command output. --- # docker_exec (Action) Run a command in an existing container, similar to `docker container exec`. Please note that due to the nature of actions, we cannot have an computed `output` attribute that contains the command output. ## Example Usage ```terraform resource "docker_image" "busybox" { name = "busybox:1.35.0" } resource "docker_container" "target" { name = "docker-exec-example" image = docker_image.busybox.image_id must_run = true command = ["sh", "-c", "sleep 300"] lifecycle { action_trigger { events = [after_create] actions = [action.docker_exec.create_file] } } } action "docker_exec" "create_file" { config { container = docker_container.target.name command = ["sh", "-c", "touch /tmp/created-by-action"] } } ``` ## Schema ### Required - `command` (List of String) Command and arguments to execute inside the container. - `container` (String) Container name or ID where the command is executed. ### Optional - `detach` (Boolean) Run command in the background. - `env` (List of String) Set environment variables for the command (`KEY=value` or `KEY`). - `env_file` (List of String) Read in environment variables from files. - `privileged` (Boolean) Give extended privileges to the command. - `tty` (Boolean) Allocate a pseudo-TTY. - `user` (String) Username or UID (format: `[:]`). - `workdir` (String) Working directory inside the container.