存在Alpine linux POSIX sh脚本,但读为“未找到”

问题描述 投票:0回答:1

我在docker配置(wait-for)中使用Linux POSIX(#!bin / sh)脚本python:3.8.1-alpine3.11

在我的docker-compose.yml中,使用以下命令加载脚本:

app:
   command: sh -c "wait-for postgres:5432 && python manage.py migrate 
                && python manage.py runserver 0.0.0.0:8000"

但是,结果为/bin/sh: wait-for: not found。当我将它装入容器时,文件肯定存在,如我所见。

通过容器内的反复试验,我发现以下方法将起作用:

/usr/src/app $  sh wait-for

简而言之,使用-c标志似乎会导致该选项。我了解sh -c calls the program sh as the interpeter and executes the script as intrepreted by this command,,但是在这种情况下会发生什么/为什么sh -c会导致脚本出现问题?

例如没有sh,该行中的其他命令将无法运行; -c无法运行,需要-c

sh python文件中使用的正确方法是什么?我应该有两个命令条目(一个用于sh -c python,另一个用于docker-compose.yml)吗?

我在docker配置(python:3.8.1-alpine3.11)中使用的是Linux POSIX(#!bin / sh)脚本。在我的docker-compose.yml中,我使用以下命令加载脚本:app:command:...

docker alpine wait-for
1个回答
0
投票

sh wait-for获取文件名,从文件名中读取命令,然后执行它们;它专门执行一个shell脚本。如果文件名不包含斜杠,则为sh -c [other commands]。这种形式总是运行一个shell脚本,这就是e.g。

© www.soinside.com 2019 - 2024. All rights reserved.