Docker Error - “jq: error: Cannot iterate over null”

前端 未结 4 1582
别跟我提以往
别跟我提以往 2020-12-15 16:47

So I\'m trying to deploy a dockerfile on Elastic Beanstalk, but I can\'t get past this error - \"jq: error: Cannot iterate over null\".

Successfully built [         


        
相关标签:
4条回答
  • 2020-12-15 17:04

    In my case issue was caused by ADD in Dockerfile instead of COPY instruction. Changing it fixed the issue.

    0 讨论(0)
  • 2020-12-15 17:06

    The problem is that your Dockerrun.aws.json file is missing the Volumes property.

    The 04pre.sh script uses the jq tool in order to query the JSON file.

    Specifically, it runs the following command on your file, which yields to an error:

    $ jq -c '.Volumes[] | [.HostDirectory, .ContainerDirectory]' < Dockerrun.aws.json
    jq: error: Cannot iterate over null
    

    Specifying an empty "Volumes" array should resolve the error.

    0 讨论(0)
  • 2020-12-15 17:06

    Note that an Elastic Beanstalk deployment to the Docker platform can fail with the "jq: error ... Cannot iterate over null..." error message in various phases of an Elastic Beanstalk deployment, for various different reasons. This can include your application (Docker container) quitting or erroring on startup.

    Although this particular reported occurrence of the problem may have been specific to a missing "Volumes" property in Dockerrun.aws.json, your problem may not be. If you get this error, then the best way to go about diagnosing the problem is to download your full EB logs and check the diagnostics in the following log file /var/log/eb-activity.log.

    If the problem was caused by your application failing to startup then you'll find the error in /var/log/eb-docker/containers/eb-current-app/unexpected-quit.log.

    0 讨论(0)
  • 2020-12-15 17:09

    If others are looking for how to avoid the Cannot iterate over null error in their own jq commands, add a question mark after []. For example

    echo '{
      "AWSEBDockerrunVersion": "1",
      "Image": {
        "Name": "blah",
        "Update": "false"
      },
      "Ports": [
        {
          "ContainerPort": "8080"
        }
      ]
    }'|jq -c '.Volumes[]?|[.HostDirectory,.ContainerDirectory]'
    

    where [] was replaced with []? does not display the error.

    From the manual:

    .[]?
        Like .[], but no errors will be output if . is not an array or object.
    
    0 讨论(0)
提交回复
热议问题