null
+ "/hello"
/docker-entrypoint.sh
+ nginx g daemon off;
대부분의 Docker 이미지에서는 /docker-entrypoint.sh 스크립트를 ENTRYPOINT로 사용하기 때문에, 해당 파일의 내용을 살펴볼 필요가 있다.
#!/bin/sh
# vim:sw=4:ts=4:et
set -e
entrypoint_log() {
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
echo "$@"
fi
}
if [ "$1" = "nginx" ] || [ "$1" = "nginx-debug" ]; then
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
entrypoint_log "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
entrypoint_log "$0: Looking for shell scripts in /docker-entrypoint.d/"
find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
case "$f" in
*.envsh)
if [ -x "$f" ]; then
entrypoint_log "$0: Sourcing $f";
. "$f"
else
# warn on shell scripts without exec bit
entrypoint_log "$0: Ignoring $f, not executable";
fi
;;
*.sh)
if [ -x "$f" ]; then
entrypoint_log "$0: Launching $f";
"$f"
else
# warn on shell scripts without exec bit
entrypoint_log "$0: Ignoring $f, not executable";
fi
;;
*) entrypoint_log "$0: Ignoring $f";;
esac
done
entrypoint_log "$0: Configuration complete; ready for start up"
else
entrypoint_log "$0: No files found in /docker-entrypoint.d/, skipping configuration"
fi
fi
exec "$@"
#!/bin/sh
→ bash, sh, zsh 어떤 쉘을 사용할지 명시한다. if [ "$1" = "nginx" ] || [ "$1" = "nginx-debug" ]; then
exec "$@"
→ 입력받은 명령어를 그대로 실행역할: 입력받은 명령어를 실행해준다. 다만, 첫번째 인자가 nginx이면 전처리를 해준다.
docker run nginx
=docker run nginx "nginx" "-g" "daemon off;"
=docker run --entrypoint ./docker-entrypoint.sh
nginx "nginx" "-g" "daemon off;"
docker run nginx ls -al
-- ①
≒ docker run --entrypoint ls
nginx -al
-- ②
= docker run --entrypoint ./docker-entrypoint.sh
nginx ls -al
-- ③
둘다 ls -al이 실행되지만, 내부적으로 동작하는 방식에는 명확한 차이가 있다.
① /docker-entrypoint.sh 스크립트가 실행 → CMD ls -al
로 덮어쓰기
→ exec "$@"에 의해 최종 명령어 exec ls -al 실행
② 기본적으로 설정된 /docker-entrypoint.sh가 무시되고 ls로 덮어쓰기
→ al은 CMD에 전달된 인자 → ls -al 실행
③ 1번과 동일하다
실행 명령어 | ENTRYPOINT 동작 | CMD 동작 | 최종 실행 명령어 |
---|---|---|---|
docker run nginx ls -al | 기본 /docker-entrypoint.sh 실행 | 덮어씌워짐 (ls -al ) | /docker-entrypoint.sh → exec ls -al |
docker run --entrypoint ls nginx -al | 기본 ENTRYPOINT 무시, ls 로 덮어쓰기 | 인자로 전달됨 (-al ) | ls -al |
docker run --entrypoint ./docker-entrypoint.sh nginx ls -al | 명시적으로 동일한 ENTRYPOINT 실행 | 인자로 전달됨 (ls -al ) | /docker-entrypoint.sh → exec ls -al |