Docker Error - "jq: error: Cannot iterate over null" Docker Error - "jq: error: Cannot iterate over null" docker docker

Docker Error - "jq: error: Cannot iterate over null"


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.jsonjq: 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.