컨테이너 런타임에 /usr/local/bin/docker-entrypoint.sh가 gosu postgres로 권한을 postgres 사용자에 내려 실행
postgres는 root 소유 700 파일을 읽을(read) 권한이 없어 스크립트 실행 불가
결국 소유자·읽기 권한 불일치로 permission denied 발생
해결
빌드 단계에서 소유자와 퍼미션을 postgres에게 맞춤
FROM postgres:14-alpine# ① 스크립트를 postgres:postgres 소유로 복사 → COPY --chown 은 Docker 17.09+ 지원COPY --chown=postgres:postgres init-scripts/ /docker-entrypoint-initdb.d/# ② 전체 디렉터리 + 파일에 실행·읽기 권한 부여RUN chmod -R 755 /docker-entrypoint-initdb.d
또는 호스트에서 미리 chmod +rx init-scripts/* 수행
커스텀 entrypoint에서 chown/chmod 후 exec gosu postgres "$@" 호출도 가능
핵심은 postgres 계정이 스크립트를 읽고 실행할 수 있게 755 또는 소유자 변경 적용