From 3c1c8f9e802db2303c64ff8388631d484e536331 Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Mon, 26 Oct 2015 21:05:53 -0700 Subject: [PATCH] Pass environment variables to docker container This change allows arbitrary environment variables to be passed to the underlying docker container. Useful when using postgres docker containers which allow for additional configuration on top of the official postgres image. See https://github.com/mcolyer/docker-postgres-wale for an example. --- README.md | 2 +- commands | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 30f0411..2efc1c4 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres ``` postgres:clone Create container then copy data from into postgres:connect Connect via psql to a postgres service -postgres:create Create a postgres service +postgres:create Create a postgres service with environment variables postgres:destroy Delete the service and stop its container if there are no links left postgres:export Export a dump of the postgres service database postgres:expose [port] Expose a postgres service on custom port if provided (random port otherwise) diff --git a/commands b/commands index 46dcadb..e9f6f07 100755 --- a/commands +++ b/commands @@ -31,8 +31,12 @@ case "$1" in touch "$LINKS_FILE" dokku_log_info1 "Starting container" + ENVIRONMENT="" + for arg in "${@:2}"; do + ENVIRONMENT="$ENVIRONMENT -e $arg" + done SERVICE_NAME=$(get_service_name "$SERVICE") - ID=$(docker run --name "$SERVICE_NAME" -v "$SERVICE_ROOT/data:/var/lib/postgresql/data" -e "POSTGRES_PASSWORD=$password" -d --restart always --label dokku=service --label dokku.service=postgres "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION") + ID=$(docker run --name "$SERVICE_NAME" -v "$SERVICE_ROOT/data:/var/lib/postgresql/data" $ENVIRONMENT -e "POSTGRES_PASSWORD=$password" -d --restart always --label dokku=service --label dokku.service=postgres "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION") echo "$ID" > "$SERVICE_ROOT/ID" dokku_log_verbose_quiet "Waiting for container to be ready"