0

I'm trying to run a simple python script that takes a json string as an argument in a docker container. However I get the following error:

Traceback (most recent call last):
  File "/root/simple.py", line 2, in <module>
    import json
ImportError: No module named json

I'm running the standard ubuntu:12.04 image. Here's how I call up the container:

docker run -v $(pwd)/:/root/ ubuntu:12.04 python /root/simple.py '[{"hi":"bye"}]' 

My simple.py script is just:

import sys
import json

configs = json.loads(sys.argv[1])

print configs

def read_option_keys(json_file):
    json_file[0]["new"] = None
    print json.dumps(json_file)

read_option_keys(configs)

Any idea why it's not returning the following as expected:

[{u'hi': u'bye'}]
[{"hi": "bye", "new": null}]
1
  • What version of python is it? json was added in 2.6. Commented Jun 12, 2014 at 19:10

2 Answers 2

1

I was able to solve the issue myself. Ubuntu image is super bare-bones. I pulled the dockerfile/python image and now it works.

Sign up to request clarification or add additional context in comments.

Comments

0

Docker is a containerized instance, so your python script has no knowledge of the outside world. You are currently running the Ubuntu image, but it doesn't contain the python standard module. You should run a python image instead or add python to your Ubuntu image

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.