manage.py collectstatic:错误:无法识别的参数: - Docker启动的shell脚本中的noinput

时间:2021-09-11 05:10:55

I'm working to launch a django-tornado hybrid app in a Docker container from a shell script and and getting --noinput as an unrecognized argument for django commands:

我正在努力从shell脚本在Docker容器中启动一个django-tornado混合应用程序,并将--noinput作为django命令的无法识别的参数:

usage: manage.py collectstatic [-h] [--version] [-v {0,1,2,3}]
                               [--settings SETTINGS] [--pythonpath PYTHONPATH]
                               [--traceback] [--no-color] [--noinput]
                               [--no-post-process] [-i PATTERN] [-n] [-c] [-l]
                               [--no-default-ignore]
manage.py collectstatic: error: unrecognized arguments: --noinput

Why would I be getting --noinput as an unrecognized argument? My Dockerfile calls a deployment shell script which performs the collectstatic and migrate commands (both with the --noinput argument, which is failing for both. I've played around with removing extraneous lines, adjusting whitespace around the command, etc, to no avail. I can run the shell script locally without any issues; it seems to only be a problem in the Docker container RUN call to the shell script.

为什么我会得到--noinput作为一个无法识别的论点?我的Dockerfile调用了一个部署shell脚本,它执行了collectstatic和migrate命令(两者都带有--noinput参数,这两个参数都失败了。我已经玩过删除多余的行,调整命令周围的空格等等,但无济于事我可以在本地运行shell脚本而不会出现任何问题;它似乎只是Docker容器对shell脚本的RUN调用中的一个问题。

Dockerfile:

FROM python:2.7

RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y python-dev
RUN apt-get install -y libmysqlclient-dev

RUN mkdir /code
ADD . /code/
WORKDIR /code
RUN pip install -r requirements.txt

CMD ["sh","./deploy.sh"]

EXPOSE 8888

deploy.sh:

#!/bin/sh
python manage.py collectstatic --noinput
python manage.py migrate --noinput
python main.py

If I run the django commands in the Dockerfile with RUN python manage.py collectstatic --noinput there is no issue, but I'm trying to get the application-specific commands in the CMD call, since I need to have database environment vars from Elastic Beanstalk for my deployment environment.

如果我使用RUN python manage.py collectstatic --noinput在Dockerfile中运行django命令没有问题,但我正在尝试在CMD调用中获取特定于应用程序的命令,因为我需要从中获取数据库环境变量我的部署环境的Elastic Beanstalk。

1 个解决方案

#1


5  

Looks like my issue was line endings in the shell script. I think sh was feeding in --noinput\R into python, so it was presenting itself in the terminal as looking like --noinput, but really it was getting a CR character as well that it was matching against.

看起来我的问题是shell脚本中的行结尾。我认为sh正在输入--noinput \ R到python中,所以它在终端中显示为看起来像--noinput,但实际上它正在获得一个CR角色以及它匹配。

When I was locally testing, it was in the Docker Quickstart terminal (where it worked), and the Docker containers were always running in Ubuntu (where it was failing).

当我在本地测试时,它位于Docker Quickstart终端(它工作的地方),而Docker容器总是在Ubuntu中运行(它失败了)。

I've hit this way in the past before where different line endings in shell scripts that were written on Windows messed things up in a Linux environment, and I need to remember how important it is to set up line endings correctly in my editors...

过去我曾经用过这种方式,之前在Windows上编写的shell脚本中的不同行结尾在Linux环境中搞砸了,我需要记住在编辑器中正确设置行结尾的重要性。 。

#1


5  

Looks like my issue was line endings in the shell script. I think sh was feeding in --noinput\R into python, so it was presenting itself in the terminal as looking like --noinput, but really it was getting a CR character as well that it was matching against.

看起来我的问题是shell脚本中的行结尾。我认为sh正在输入--noinput \ R到python中,所以它在终端中显示为看起来像--noinput,但实际上它正在获得一个CR角色以及它匹配。

When I was locally testing, it was in the Docker Quickstart terminal (where it worked), and the Docker containers were always running in Ubuntu (where it was failing).

当我在本地测试时,它位于Docker Quickstart终端(它工作的地方),而Docker容器总是在Ubuntu中运行(它失败了)。

I've hit this way in the past before where different line endings in shell scripts that were written on Windows messed things up in a Linux environment, and I need to remember how important it is to set up line endings correctly in my editors...

过去我曾经用过这种方式,之前在Windows上编写的shell脚本中的不同行结尾在Linux环境中搞砸了,我需要记住在编辑器中正确设置行结尾的重要性。 。