Skip to content

Run scripts on each startup #882

Closed
Closed
@jonasgroenke

Description

@jonasgroenke

Hey, can we add a possibility for scripts which are executed on every startup? Not only on initializing the database.

My use case is that I have init scripts which are creating some users specified in the secret files.
When I now change the passwords in the secrets, I have to completely remove the database just for updating the passwords.
Or do I miss something and there is already something for my use case?

My current solution is to add a custom entrypoint and call some methods from the official one. But other people might be also interested in and we can improve it.

#!/bin/bash
set -e
source /usr/local/bin/docker-entrypoint.sh

docker_setup_env "$@"

if [ "$(id -u)" = "0" ]; then
  mysql_note "Switching to dedicated user 'mysql'"
  exec gosu mysql "$BASH_SOURCE" "$@"
fi

mysql_note "Starting temporary server"
docker_temp_server_start "$@"
mysql_note "Temporary server started."

# Set mysql passwords from secrets
docker_process_init_files /docker-entrypoint-initdb.d/01-create-user.sh

mysql_note "Stopping temporary server"
docker_temp_server_stop
mysql_note "Temporary server stopped"

exec "$@"`

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionUsability question, not directly related to an error with the image

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions