Running python code in Docker

  1. Create app.py using vi app.py with just the following line of python code:

     print "Hello, world here!!!"
    
    • Press <Esc>

    • Type :x

  2. Create a docker file using vi Dockerfile and add the following:

     FROM python:2.7
    
     ADD app.py /
    
     CMD [ "python", "./app.py" ]
    
    • Press <Esc>

    • Type :x

  3. Build the docker image using docker build -t python-new-world . where python-new-world is the image name and you will get the results as shown below:

    alt text

  4. Run the docker image using docker run python-new-world and you will get the following output in terminal window as shown below:

    alt text