Error response from daemon: failed to parse Dockerfile: Syntax error - can't find = in "RUN". Must be of the form: name=value

Viewed 2891

When I'm trying to build the Dockerfile from aws codebuild I'm getting the this error as "Error response from daemon: failed to parse Dockerfile: Syntax error - can't find = in "RUN". Must be of the form: name=value" In code build I'm using ubuntu as environmment with aws/codebuild/standard 5.0 runtime version. Here is my Dockerfile and buildspec.yml:

FROM alipine:3.12
ARG SONARQUBE_VERSION=8.9.0.43852
COPY ./sonarqube-8.9.0.43852.zip   /opt/'sonarqube-${SONARQUBE_VERSION}.zip'
RUN chmod 777 /opt/sonarqube-8.9.0.43852.zip
---------------
--------------

COPY --chown=sonarqube:sonarqube run.sh sonar.sh ${SONARQUBE_HOME}/bin/
USER sonarqube
RUN chmod 777 ${SONARQUBE_HOME}/bin/run.sh; \
RUN chmod 777 ${SONARQUBE_HOME}/bin/sonar.sh
VOLUME $SONARQUBE_HOME
WORKDIR ${SONARQUBE_HOME}
EXPOSE 9000
ENTRYPOINT ["/opt/sonarqube/bin/run.sh"]
CMD ["/opt/sonarqube/bin/sonar.sh"]

And the below is my buildspec.yml

version: 0.2

phases:
  install:
    runtime-versions:
      java: corretto11

  pre_build:
    commands:
      - echo Logging in to Amazon ECR.....
      - aws --version
      - aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin <MyAccountId>.dkr.ecr.eu-west-1.amazonaws.com/sonarqube
      
  build:
    commands:
      - aws s3 cp s3://ravitej/SonarQube/sonarqube-8.9.0.43852.zip  .
      - chmod +x sonarqube-8.9.0.43852.zip
      - echo $(pwd)
      - echo Build started on `date`
      - echo Building the Docker image...
      - echo $(docker version)
      - REPOSITORY_URI=<MyAccountID>.dkr.ecr.eu-west-1.amazonaws.com/sonarqube
      - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - docker build -t $REPOSITORY_URI:$IMAGE_TAG .
      
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker images...
      - docker push $REPOSITORY_URI:$IMAGE_TAG
      - echo Writing image definitions file...
      - printf '[{"name":"sonarqube","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
      - echo imagedefinitions.json
artifacts:
    files: imagedefinitions.json

Banging my head againt the table for the past 2 days.

Please help.. This is the error from code build: enter image description here

2 Answers

I just had a similar problem which lead me here and the issue was a trailing \ in my Dockerfile. In your case I guess it is this line:

RUN chmod 777 ${SONARQUBE_HOME}/bin/run.sh; \

Which causes problems for the next line.

This also happens when you try to add a comment using hash at the end of the line, e.g. like # OK here:

$ cat Dockerfile
[..]
ENV RSTUDIO_VER=1.3.1073 # OK
[..]

The docker build's parser won't like it!

$ docker build -t mirekphd/ml-cpu-r40-rs-cust .
Sending build context to Docker daemon  142.2MB

Error response from daemon: failed to parse Dockerfile: Syntax error - can't find = in "#". Must be of the form: name=value
Related