Add the ability to run containers in detached mode

This commit is contained in:
Jose Diaz-Gonzalez
2016-05-02 00:02:37 -04:00
parent e9447a26d9
commit 8597b692ee
3 changed files with 19 additions and 2 deletions

View File

@@ -32,6 +32,13 @@ dokku --rm-container run node-js-app ls -lah
dokku --rm run node-js-app ls -lah
```
Finally, you may wish to run a container in "detached" mode via the `--detach` dokku flag. Note that you may not use the `--rm-container` or `--rm` flags when running containers in detached mode, and attempting to do so will result in the `--detach` flag being ignored.
```shell
dokku --detach run node-js-app ls -lah
# returns the ID of the new container
```
### Using `run` for cron tasks
You can always use a one-off container to run an application task:

View File

@@ -20,8 +20,15 @@ dokku_run_cmd() {
local DOCKER_ARGS=$(: | plugn trigger docker-args-run "$APP" "$IMAGE_TAG")
[[ "$DOKKU_TRACE" ]] && local DOCKER_ARGS+=" -e TRACE=true "
[[ "$DOKKU_RM_CONTAINER" ]] && local DOKKU_RUN_OPTS="--rm"
has_tty && local DOKKU_RUN_OPTS+=" -i -t"
local DOKKU_RUN_OPTS=""
if [[ "$DOKKU_RM_CONTAINER" ]]; then
DOKKU_RUN_OPTS+=" --rm"
elif [[ "$DOKKU_DETACH_CONTAINER" ]]; then
DOKKU_RUN_OPTS+=" --detach"
fi
has_tty && DOKKU_RUN_OPTS+=" -i -t"
is_image_herokuish_based "$IMAGE" && local EXEC_CMD="/exec"
# shellcheck disable=SC2086
docker run $DOKKU_GLOBAL_RUN_ARGS $DOKKU_RUN_OPTS $DOCKER_ARGS $IMAGE $EXEC_CMD "$@"

View File

@@ -228,6 +228,9 @@ parse_args() {
--quiet)
export DOKKU_QUIET_OUTPUT=1
;;
--detach)
export DOKKU_DETACH_CONTAINER=1
;;
--trace)
export DOKKU_TRACE=1
;;