为什么使用.SH脚本作为入口点时,为什么Docker无法运行正确的CMD?

发布于 2025-01-18 03:21:22 字数 2060 浏览 1 评论 0原文

我对Docker的新手(至少要比其他人构建的图像还要多),并且我陷入了这一模型。我正在使用Deno构建一个应用程序,并试图在Docker中运行它。我的基本形象是官员使用Alpine 的Deno图像,它使用.SH作为入口点。官方图像中定义的输入点脚本应该查看CMD中的第一个参数(在这种情况下为“运行”),如果它在列表中(它是),请使用DENO命令运行。相反,我有一个错误。

CMD

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

错误

/bin/sh: run: not found

当我在DENO中进行硬码时,

运行良好。 cmd deno run - allow-net - allow-read-lock = lock.json mod.ts

我不知道为什么它不通过脚本作为入口点来工作。我在做什么错?

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 "$@"

我的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

基本图像信息在这里

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文