Skip to content

Trying to override docker-entrypoint.sh sourcing original one fails #452

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
typoworx-de opened this issue Jul 29, 2022 · 2 comments
Closed

Comments

@typoworx-de
Copy link

I'm trying to override docker-entrypoint.sh to implement a feature being able to import sql-patches (not initdb).

my script looks like this and I'm overriding entrypoint in my docker-compose.yml

docker-compose.overrides.yml

version: '3.6'

services:
  db:
    entrypoint: bash /root/bin/custom-entrypoint.sh
  volumes:
    - ./docker/db/bin/:/root/bin

/root/bin/custom-entrypoint.sh (inside container)

#!/bin/bash

echo "Running entrypoint $0"

source /docker-entrypoint.sh
_main "$@"

# custom stuff goes here

Restarting the stack results in the following error in the new entrypoint:

_main command not found

It looks like the source'ing is somehow ignored for my own entrypoint script.

Is there any draft how to properly do this? I think the last line in the original-entrypoint in this project already proposes a draft on how to use it, but for some reason the functions of this script are not sourced/imported in the custom entrypoint :-/

@yosifkit
Copy link
Contributor

yosifkit commented Jul 29, 2022

  1. add a set -e and you'll see it is failing at the source /docker-entrypoint.sh line
    • swap that to source /usr/local/bin/docker-entrypoint.sh or source "$(command -v docker-entrypoint.sh)":
      COPY docker-entrypoint.sh /usr/local/bin/
  2. Replacing entrypoint likely resets command too, so you need to also supply that for "$@" to work as expected
  3. Just running _main is probably not going to do what you want as it ends in basically exec mysqld and so will never return to your script to run anything else.

@grooverdan
Copy link
Member

The location of the entrypoint script isn't what you expected.

$ podman run --rm -ti mariadb:10.6 find . -name docker-entrypoint.sh
./usr/local/bin/docker-entrypoint.sh

# for free to join this conversation on GitHub. Already have an account? # to comment
Development

No branches or pull requests

3 participants