Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit cab04d2

Browse files
authored
Merge pull request #1 from amouat/main
Initial version.
2 parents e8fb216 + b49a29a commit cab04d2

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM cgr.dev/chainguard/wolfi-base
2+
3+
COPY entrypoint.sh /
4+
RUN chmod +x entrypoint.sh
5+
6+
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,31 @@
11
# container-entrypoint
2-
Simple script for use as entrypoint to a container
2+
3+
Simple script for use as entrypoint to a container.
4+
5+
Attempts to intelligently decide if a command is an argument to an application or calling as system
6+
command. In other words, it is intended to allow all the following use cases:
7+
8+
```
9+
$ docker run --rm foo --version
10+
foo 0.8
11+
12+
$ docker run --rm foo echo boo
13+
boo
14+
15+
$ docker run -it foo sh
16+
/ #
17+
/ # exit
18+
```
19+
20+
To use the script, set it as the ENTRYPOINT in a Dockerfile or equivalent, making sure it is
21+
executable. Also set the environment variable `BASE_COMMAND` appropriately. For example:
22+
23+
```
24+
$ docker run --rm -e BASE_COMMAND="uname" my_image -a
25+
Linux f3c6b322e73a 5.15.49-linuxkit #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 aarch64 Linux
26+
```
27+
28+
We've used `-e` for the purposes of this demo, but the variable should be set in the Dockerfile or
29+
by editing the script.
30+
31+
This script is based on the [NodeJS entrypoint script](https://github.com/nodejs/docker-node/blob/e75fa5270326ffaff8fee03153f3bf16860084d4/19/bullseye-slim/docker-entrypoint.sh).

entrypoint.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# To use this script, set BASE_COMMAND to the name of the base application you want to run e.g.
5+
# "curl".
6+
#
7+
# This script is based on the
8+
# Run command with base application if the first argument contains a "-" or is not a system command.
9+
# The last part inside the "{}" is a workaround for the following bug in ash/dash:
10+
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=874264
11+
if [ -z "$BASE_COMMAND" ]; then
12+
echo "WARNING: Entryscript in use but \$BASE_COMMAND not configured"
13+
elif [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ] || { [ -f "${1}" ] && ! [ -x "${1}" ]; }; then
14+
set -- $BASE_COMMAND "$@"
15+
fi
16+
17+
exec "$@"

test.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
set -e
3+
4+
docker build -t command_test .
5+
docker run --rm -e BASE_COMMAND="uname" command_test -a
6+
docker run --rm -e BASE_COMMAND="ls" command_test
7+
docker run --rm -e BASE_COMMAND="echo" command_test foo bar
8+
docker run --rm command_test ls
9+
10+
docker rmi command_test
11+
12+

0 commit comments

Comments
 (0)