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

大憨熊 提交于 2019-11-29 05:28:32

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.

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!