diff --git a/lib/kamal/commands/accessory.rb b/lib/kamal/commands/accessory.rb index 4a76d6f6..441aae75 100644 --- a/lib/kamal/commands/accessory.rb +++ b/lib/kamal/commands/accessory.rb @@ -55,14 +55,14 @@ class Kamal::Commands::Accessory < Kamal::Commands::Base def execute_in_existing_container(*command, interactive: false) docker :exec, - ("-it" if interactive), + (docker_interactive_args if interactive), service_name, *command end def execute_in_new_container(*command, interactive: false) docker :run, - ("-it" if interactive), + (docker_interactive_args if interactive), "--rm", *network_args, *env_args, diff --git a/lib/kamal/commands/app/execution.rb b/lib/kamal/commands/app/execution.rb index e1289fd8..31c18735 100644 --- a/lib/kamal/commands/app/execution.rb +++ b/lib/kamal/commands/app/execution.rb @@ -1,7 +1,7 @@ module Kamal::Commands::App::Execution def execute_in_existing_container(*command, interactive: false, env:) docker :exec, - ("-it" if interactive), + (docker_interactive_args if interactive), *argumentize("--env", env), container_name, *command @@ -9,7 +9,7 @@ module Kamal::Commands::App::Execution def execute_in_new_container(*command, interactive: false, detach: false, env:) docker :run, - ("-it" if interactive), + (docker_interactive_args if interactive), ("--detach" if detach), ("--rm" unless detach), "--network", "kamal", diff --git a/lib/kamal/commands/base.rb b/lib/kamal/commands/base.rb index ba3b86ba..08c272f8 100644 --- a/lib/kamal/commands/base.rb +++ b/lib/kamal/commands/base.rb @@ -122,5 +122,9 @@ module Kamal::Commands def ensure_local_buildx_installed docker :buildx, "version" end + + def docker_interactive_args + STDIN.isatty ? "-it" : "-i" + end end end