diff --git a/docs/processes/one-off-tasks.md b/docs/processes/one-off-tasks.md index 11419dc94..853b90bf2 100644 --- a/docs/processes/one-off-tasks.md +++ b/docs/processes/one-off-tasks.md @@ -2,7 +2,7 @@ ``` run [-e|--env KEY=VALUE] [--no-tty] # Run a command in a new container using the current app image -run:detached [-e|-env KEY=VALUE] [--no-tty] # Run a command in a new detached container using the current app image +run:detached [-e|-env KEY=VALUE] [--force-tty] # Run a command in a new detached container using the current app image run:list [--format json|stdout] [] # List all run containers for an app run:logs [-h] [-t] [-n num] [-q] # Display recent log output for run containers run:stop # Stops all run containers for an app or a specified run container @@ -73,6 +73,12 @@ dokku run:detached node-js-app ls -lah # returns the ID of the new container ``` +To start a detached container with a tty, specify the `--force-tty` flag. Containers will still exit upon command termination, but can be attached to as long as they are running. + +```shell +dokku run:detached --force-tty node-js-app bash +``` + ### Displaying one-off container logs You can easily get logs of all one-off containers for an app using the `logs` command: diff --git a/plugins/run/help-functions b/plugins/run/help-functions index c20ec4746..d145031ae 100755 --- a/plugins/run/help-functions +++ b/plugins/run/help-functions @@ -28,7 +28,7 @@ fn-help-content() { declare desc="return help content" cat < , Run a command in a new container using the current app image - run:detached [-e|-env KEY=VALUE] [--no-tty|--force-tty] , Run a command in a new detached container using the current app image + run:detached [-e|-env KEY=VALUE] [--force-tty] , Run a command in a new detached container using the current app image run:list [--format json|stdout] , List all run containers for an app run:logs [-h] [-t] [-n num] [-q], Display recent log output for run containers run:stop , Stops all run containers for an app or a specified run container diff --git a/plugins/run/internal-functions b/plugins/run/internal-functions index a09694c66..b4ccfc2ce 100755 --- a/plugins/run/internal-functions +++ b/plugins/run/internal-functions @@ -5,6 +5,8 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" fn-run() { declare desc="runs command in container" + declare CMD="$1" + shift 1 declare APP="" local CRON_ID @@ -54,6 +56,10 @@ fn-run() { esac done + if [[ "$CMD" == "run:detached" ]] && [[ "$DOKKU_FORCE_TTY" != "true" ]]; then + export DOKKU_DISABLE_TTY=true + fi + if [[ "$DOKKU_DISABLE_TTY" == "true" ]] && [[ "$DOKKU_FORCE_TTY" == "true" ]]; then dokku_log_fail "Cannot specify both --force-tty and --no-tty" fi @@ -70,7 +76,7 @@ cmd-run() { [[ "$1" == "$cmd" ]] && shift 1 export DOKKU_RM_CONTAINER=1 - fn-run "$@" + fn-run "$cmd" "$@" } cmd-run-detached() { @@ -79,9 +85,8 @@ cmd-run-detached() { [[ "$1" == "$cmd" ]] && shift 1 export DOKKU_DETACH_CONTAINER=1 - export DOKKU_DISABLE_TTY=true export DOKKU_RM_CONTAINER=1 - fn-run "$@" + fn-run "$cmd" "$@" } cmd-run-list() {