1 year ago

#352195

test-img

Matt Flamm

Why does docker fail to run correct CMD when using .sh script as entrypoint?

I'm relatively new to docker (at least to do more than run images others had built) and I'm stuck on this one. I'm building an app using Deno and trying to get it running in docker. my base image is the official deno image with Alpine, which uses an .sh as its entry point. The entry point script as defined in the official image is supposed to look at the first argument in the CMD (in this case "run") and if it's in a list (which it is), run it with the deno command. Instead I get an error.

the CMD

CMD run --allow-net --allow-read --lock=lock.json mod.ts

the error

/bin/sh: run: not found

when I hard code in the deno, it runs fine.

CMD deno run --allow-net --allow-read --lock=lock.json mod.ts

I can't figure why it's not working through the script as an entry point. What am I doing wrong?

docker-entry.sh

#!/bin/sh
set -e

if [ "$1" != "${1#-}" ]; then
    # if the first argument is an option like `--help` or `-h`
    exec deno "$@"
fi

case "$1" in
    bundle | cache | compile | completions | coverage | doc | eval | fmt | help | info | install | lint | lsp | repl | run | test | types | uninstall | upgrade | vendor )
    # if the first argument is a known deno command
    exec deno "$@";;
esac

exec "$@"

my Dockerfile

FROM denoland/deno:alpine-1.19.2

# The port that your application listens to.
EXPOSE MYPORTNUMBER

WORKDIR /app

# Prefer not to run as root.
USER deno

# Cache the dependencies as a layer (the following two steps are re-run only when deps.ts is modified).
# Ideally cache deps.ts will download and compile _all_ external files used in main.ts.
COPY deps.ts .
RUN deno cache deps.ts

# These steps will be re-run upon each file change in your working directory:
ADD . .
# Compile the main app so that it doesn't need to be compiled each startup/entry.
RUN deno cache mod.ts

CMD run --allow-net --allow-read --lock=lock.json mod.ts

base image info here

docker

shell

dockerfile

deno

entry-point

0 Answers

Your Answer

Accepted video resources