Docker newbie stuck

Hello,
Just getting started with docker and get stuck at step 2, and I am new to Python too and I got a Python problem, I think.
I am using a MacOS Sierra with Python 3.6+ but the tutorial is using Python 2.7. When I follow the tutorial:-

docker run -p 4000:80 friendlyhello

File “app.py”, line 24
app.run(host=‘0.0.0.0’, port=80)
^
IndentationError: expected an indented block

The code for app.py. The link for the code is here

from flask import Flask
from redis import Redis, RedisError
import os
import socket

# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)

app = Flask(__name__)

@app.route("/")
def hello():
    try:
        visits = redis.incr("counter")
    except RedisError:
        visits = "<i>cannot connect to Redis, counter disabled</i>"

    html = "<h3>Hello {name}!</h3>" \
           "<b>Hostname:</b> {hostname}<br/>" \
           "<b>Visits:</b> {visits}"
    return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80)

I have deleted the 1st copy paste and retyped the code but still getting the same error - IndentationError: …
Appreciate the help.

Hi,

Try to build the image with the below command

docker build ./ -t imagename

I too faced the same error. got resolved by this.

Putting in an extra space or leaving one out where it is needed will surely generate an error message . Some common causes of this error include:

  • Forgetting to indent the statements within a compound statement
  • Forgetting to indent the statements of a user-defined function.

The error message IndentationError: expected an indented block would seem to indicate that you have an indentation error. It is probably caused by a mix of tabs and spaces. The indentation can be any consistent white space . It is recommended to use 4 spaces for indentation in Python, tabulation or a different number of spaces may work, but it is also known to cause trouble at times. Tabs are a bad idea because they may create different amount if spacing in different editors .