Skip to content

Add file filter on /docker-entrypoint-initdb.d scripts #265

Closed
@joraff

Description

@joraff

Initializing a container results in ERROR: Can't initialize batch_readline - may be the input source is a directory or a block device. when a mounted file is missing from the host due to docker's behavior to create an empty directory for any missing mounted file.

root@8238788eac51:/# ls -la /docker-entrypoint-initdb.d/
total 8
drwxr-xr-x  3 root root 4096 Feb 15 19:09 .
drwxr-xr-x 58 root root 4096 Feb 15 19:32 ..
drwxr-xr-x  2 root root   68 Feb 15 19:09 database.sql
root@8238788eac51:/# for f in /docker-entrypoint-initdb.d/*; do echo $f; done                                                           
/docker-entrypoint-initdb.d/database.sql

Can a simple file test be added here?

for f in /docker-entrypoint-initdb.d/*; do

for f in $(find /docker-entrypoint-initdb.d/* -type f); do
    case "$f" in
            *.sh)     echo "$0: running $f"; . "$f" ;;
            *.sql)    echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;;
            *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;;
            *)        echo "$0: ignoring $f" ;;
        esac
    echo
done

or

for f in /docker-entrypoint-initdb.d/*; do
    if [ ! -f $f ]; then
      echo "ignoring $f: not a regular file";
      continue
    fi
    case "$f" in
            *.sh)     echo "$0: running $f"; . "$f" ;;
            *.sql)    echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;;
            *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;;
            *)        echo "$0: ignoring $f" ;;
        esac
    echo
done

Edit: reorganized paragraphs

Metadata

Metadata

Assignees

No one assigned

    Labels

    RequestRequest for image modification or feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions