30
loading...
This website collects cookies to deliver better user experience
FROM alpine
CMD ["echo", "Hello, world!"]
FROM alpine
ENTRYPOINT ["echo"]
CMD ["Hello, world!"]
entrypoint.sh
or docker-entrypoint.sh
is executed as entrypoint.FROM alpine
ENV WORKER_SLEEP=5
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
#!/bin/sh
set -e
echo 'Work, Work!'
sleep $WORKER_SLEEP
echo 'Hello, World!'
set -e
tells the shell to abort on first error. You can also set the -x
flag to see the execution plan.exec $@
at the end of the entrypoint.sh
.FROM alpine
ENV WORKER_SLEEP=5
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
CMD echo 'Hello, World!'
#!/bin/sh
set -e
echo 'Work, Work!'
sleep $WORKER_SLEEP
exec $@
$@
stands for the complete argument list. While the individual positional arguments can be accessed by $n
where n
stands for the arguments position in the list. e.g. $1
, $2
. This script uses the exec Bash command so that the final running application becomes the container’s PID 1. This allows the application to receive any Unix signals sent to the container. For more, see the ENTRYPOINT reference.
exec
. Below the arguments are used like in the early entry point example but only after performing the work.FROM alpine
ENV WORKER_SLEEP=5
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
CMD ["Hello, World!"]
#!/bin/sh
set -e
echo 'Work, Work!'
sleep $WORKER_SLEEP
echo "$@"
exec $@
it is echo $@
so anything that was passed to as command
will get echoed. You can also use exec echo "$@"
which would run the echo
command with PID 1 again.shift
to correct the users mistakes.Dockerfile
stays the same, but now we are checking if the first argument is echo
and if so we remove if by shifting the argument list. Shift
removes the first argument from the left and shifts the indices of the remaining arguments to the left.#!/bin/sh
set -e
echo 'Work, Work!'
sleep $WORKER_SLEEP
[[ "$1" == "echo" ]] && shift
echo "$@"
docker run my-image Hello, World! # or
docker run my-image echo Hello, World!
#!/bin/sh
# vim:sw=4:ts=4:et
set -e
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
exec 3>&1
else
exec 3>/dev/null
fi
if [ "$1" = "nginx" -o "$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
echo >&3 "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
echo >&3 "$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
*.sh)
if [ -x "$f" ]; then
echo >&3 "$0: Launching $f";
"$f"
else
# warn on shell scripts without exec bit
echo >&3 "$0: Ignoring $f, not executable";
fi
;;
*) echo >&3 "$0: Ignoring $f";;
esac
done
echo >&3 "$0: Configuration complete; ready for start up"
else
echo >&3 "$0: No files found in /docker-entrypoint.d/, skipping configuration"
fi
fi
exec "$@"
# _mongod_hack_ensure_no_arg '--some-unwanted-arg' "$@"
# set -- "${mongodHackedArgs[@]}"
_mongod_hack_ensure_no_arg_val() {
local ensureNoArg="$1"; shift
mongodHackedArgs=()
while [ "$#" -gt 0 ]; do
local arg="$1"; shift
case "$arg" in
"$ensureNoArg")
shift # also skip the value
continue
;;
"$ensureNoArg"=*)
# value is already included
continue
;;
esac
mongodHackedArgs+=( "$arg" )
done
}