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

前端 未结 4 1589
别跟我提以往
别跟我提以往 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: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.
    

提交回复
热议问题