/ bin / bash: ungültiges optionash: -

Nov 21 2020

Ich bin neu bei Docker. Tut mir leid, wenn dies eine Noob-Frage ist :(

Ein Freund hat mir sein Projekt mitgeteilt und ich versuche, den Container zu erstellen, aber ich habe einen Fehler.

Hier ist meine Eingabe:

docker build -t project-py -f project-py/prod/Dockerfile .

Und hier ist der Fehler:

 => ERROR [19/27] RUN build.sh                                                                                     0.2s
------
 > [19/27] RUN build.sh:
: invalid optionash: -
------
failed to solve with frontend dockerfile.v0: failed to build LLB: executor failed running [/bin/sh -c build.sh]: runc did not terminate sucessfully

Was ich bisher verstehe ist, dass er diese Zeile in meinem build.sh nicht versteht: #!/bin/bash -e

Ich habe einen Test gemacht:

  • Lassen Sie die Datei build.sh leer = funktioniert
  • entferne das "-e" = gib dem Fehler einen schlechten Interpreter

Mein Freund hat den Fehler nicht ...

Hier ist mein Dockerfile:

# based on https://github.com/dockerfiles/django-uwsgi-nginx
FROM amazonlinux

ENV HOME /home/appuser
ENV AWS_DEFAULT_REGION us-east-1

# Install required packages and remove the cache when done
RUN yum update -y && yum install -y \
    amazon-linux-extras awscli git \
    make glibc-devel gcc patch mysql-devel \
    enchant pyOpenSSL python3 python3-devel python3-pip python3-setuptools python-imaging \
    which vim git \
    && yum clean all

RUN cd /tmp && \
    curl -O https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm && \
    rpm -U ./amazon-cloudwatch-agent.rpm && \
    rm amazon-cloudwatch-agent.rpm

RUN amazon-linux-extras enable nginx1 && yum install -y nginx && yum clean all

#breaking this up to benefit from docker caching...
RUN pip3 install --upgrade pip supervisor uwsgitop \
  && useradd -m appuser \
    && chown -R appuser:appuser /home/appuser \
    && mkdir /var/log/project

# this is our log config
COPY project-py/prod/amazon-cloudwatch-agent/amazon-cloudwatch-agent.json /opt/aws/amazon-cloudwatch-agent/etc/config.json
# this is a hacked version of the ctl script that doesn't use systemd/initd to start it
COPY project-py/prod/amazon-cloudwatch-agent/amazon-cloudwatch-agent-ctl /opt/aws/amazon-cloudwatch-agent/bin/

USER appuser

# COPY requirements.txt and RUN pip install BEFORE adding the rest of your code, this will cause Docker's caching mechanism
# to prevent re-installing all your dependencies when you made a change a line or two in your app.
COPY --chown=appuser:appuser project-py/requirements/production.txt $HOME/project-py/requirements.txt RUN python3 -m venv $HOME/venv && /bin/bash -c "source $HOME/venv/bin/activate; pip3 install -r $HOME/project-py/requirements.txt"

# add our stuff. break it up so that we can benefit from docker caching
COPY --chown=appuser:appuser project-docs $HOME/project-docs COPY --chown=appuser:appuser project-static $HOME/project-static
COPY --chown=appuser:appuser project-www $HOME/project-www COPY --chown=appuser:appuser project-py/assets/fonts $HOME/project-py/assets/fonts
COPY --chown=appuser:appuser project-py/*.py $HOME/project-py/ COPY --chown=appuser:appuser project-py/project $HOME/project-py/project
COPY --chown=appuser:appuser project-py/templates $HOME/project-py/templates COPY --chown=appuser:appuser project-py/tools $HOME/project-py/tools
COPY project-py/prod/build.sh /usr/local/bin/
RUN build.sh

Hier ist das build.sh:

#!/bin/bash -e

source $HOME/venv/bin/activate echo "compiling translations..." pybabel compile --use-fuzzy -d $HOME/project-py/hourglass/translations

Ich arbeite an W10 Build 2004 auf einem Surface Pro 7 mit dieser Docker-Version:

Client: Docker Engine - Community
 Cloud integration: 1.0.2
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 17:00:27 2020
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46d9d
  Built:            Wed Sep 16 17:07:04 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Vielen dank für Deine Hilfe

Antworten

BMitch Nov 22 2020 at 02:50

Die Datei scheint mit Windows-Zeilenvorschüben (cr + lf) gespeichert zu sein. Speichern Sie das Skript mit Linux-Zeilenvorschüben (lf), da Linux das Wagenrücklaufzeichen als Teil der Befehlszeile interpretiert.