dokku / dokku-mariadb

a mariadb plugin for dokku
MIT License
73 stars 26 forks source link

Start a new (removed) container #31

Closed ignlg closed 8 years ago

ignlg commented 8 years ago

I want to call for ideas to add a new command to deploy a new container with existent configuration.

This was the case: While I was cleaning up docker containers and images, I destroyed a dokku-mariadb container that was stopped earlier. I've found that there's no command to deploy again a dokku-mariadb container. mariadb:create creates a new configuration and mariadb:start doesn't found the old container.

I ended up creating a new command mariadb:deploy that is similar to mariadb:create but it reads the actual configuration to deploy the container.

As I could end up pushing the feature to other plugins like dokku-mongo, etc, I would want to quickly discuss with you the right name and description for the command.

What do you think?

josegonzalez commented 8 years ago

I'm not sure what you are trying to do. Do you mean the container was destroyed so you needed another one with the same config/volume?

ignlg commented 8 years ago

Exactly. I need to start a new container but keep the config/volume.

create says that the service already exists. start says that no container exists.

And both are right.

I was stuck so I created this command:

  $PLUGIN_COMMAND_PREFIX:deploy)
    [[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
    [[ -d "$PLUGIN_DATA_ROOT/$2" ]] || dokku_log_fail "$PLUGIN_SERVICE service $2 does not exist"
    SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; LINKS_FILE="$SERVICE_ROOT/LINKS"

    if ! docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " ; then
      dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION not found"
    fi

    rootpassword=$(cat "$SERVICE_ROOT/ROOTPASSWORD")
    password=$(cat "$SERVICE_ROOT/PASSWORD")

    dokku_log_info1 "Starting container"
    SERVICE_NAME=$(get_service_name "$SERVICE")
    ID=$(docker run --name "$SERVICE_NAME" -v "$SERVICE_ROOT/data:/var/lib/mysql" -e "MYSQL_ROOT_PASSWORD=$rootpassword" -e MYSQL_USER=mariadb -e "MYSQL_PASSWORD=$password" -e "MYSQL_DATABASE=$SERVICE" -d --restart always --label dokku=service --label dokku.service=mariadb "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION")
    echo "$ID" > "$SERVICE_ROOT/ID"

    dokku_log_verbose_quiet "Waiting for container to be ready"
    docker run --rm --link "$SERVICE_NAME:$PLUGIN_COMMAND_PREFIX" dokkupaas/wait > /dev/null

    dokku_log_info2 "$PLUGIN_SERVICE container created: $SERVICE"
    dokku "$PLUGIN_COMMAND_PREFIX:info" "$SERVICE"
    ;;

That is like create but it reads the configuration instead of creating/writing it.

josegonzalez commented 8 years ago

start should probably warn and then create the container. That seems reasonable to me. Mind creating a pr with that functionality? I can port it to the other containers once you do.

ignlg commented 8 years ago

Sure, I was waiting to discuss if it should be a new command or not to create a PR. And I have the answer now :)

josegonzalez commented 8 years ago

Closed by #44