Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

/bin/bash: invalid optionash: -

Tags:

bash

docker

I'm new with Docker, so sorry if this is a noob question :(

A friend shared with me his project and I'm trying to create the container but I have an error.

Here is my input:

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

And here is the error:

 => 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

What I understand so far is he doesn't understand this line in my build.sh : #!/bin/bash -e

I have done some test:

  • leave the build.sh file blank = works
  • remove the "-e" = give the error bad interpreter

My friend doesn't have the error...

Here is my 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

Here is the build.sh :

#!/bin/bash -e

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

I'm working on W10 build 2004 on a surface Pro 7, with this version of docker :

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

Thanks a lot for your help

like image 972
Jordan Matas Avatar asked Oct 20 '25 17:10

Jordan Matas


2 Answers

The file appears to be saved with Windows linefeeds (cr+lf). Save the script with Linux linefeeds (lf) since Linux will interpret the carriage return character as part of the command line.

like image 131
BMitch Avatar answered Oct 23 '25 06:10

BMitch


In Dockfile add this line before RUN ./setup.sh

RUN cat setup.sh | sed '1 s/\r$//' > setup.sh

basically, it will remove \r from the first line.

like image 42
Avinash katariya Avatar answered Oct 23 '25 08:10

Avinash katariya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!