I want to execute curl using bash script inside the Docker container.

This is my script file script.sh that I added to the container:

curl -X POST http://localhost:9200/tests/test -d usr/share/elasticsearch/data/test.json

The content of json file is the following (the idea to add \ comes from this thread):


When I enter into the running Docker container and do bash myscript.sh, the result is:

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}}

However, if I change the script to this one:

curl -X POST http://localhost:9200/tests/test -d "{\"id\":\"978-1-60741-503-9\",\"doi\":\"\"}"

then it works without errors.

So, why doesn't it like the json file???


When I add @ behind usr/ as suggested in comments, I get the following error:

Warning: Couldn't read data from file Warning: "usr/share/elasticsearch/data/test.json", this makes an empty Warning: POST. % Total % Received % Xferd Average Speed Time
Time Time Current Dload Upload Total Spent Left Speed 100 201 100 201 0 0 740 0 --:--:-- --:--:-- --:--:-- 738 {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse, document is empty"}],"type":"mapper_parsing_exception","reason":"failed to parse, document is empty"},"status":400}

The file test.json:

  • Try this -d @usr/share/elasticsearch/data/test.json. Note the use of @ – Fazlin Jul 15 '16 at 14:19

The json file passed as argument to curl -d should be preceded by @ symbol.

curl -X POST http://localhost:9200/tests/test -d @usr/share/elasticsearch/data/test.json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.