Docker Community Forums

Share and learn in the Docker community.

Docker Compose Tutorial Issues


(Chrisdoan) #1

Hi all,

I’m a beginner in programming as well as docker. I was following the Docker Compose tutorial here: https://docs.docker.com/compose/gettingstarted/. I followed every step and can’t seem to start the application with docker-compose up I got this error:

web_1 | Traceback (most recent call last):
web_1 | File “app.py”, line 7, in
web_1 | app = Flask(test)
web_1 | NameError: name “test” is not defined

I created app.py just like in the tutorial:
import time

import redis
from flask import Flask


app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)


def get_hit_count():
    retries = 5
    while True:
        try:
            return cache.incr('hits')
        except redis.exceptions.ConnectionError as exc:
            if retries == 0:
                raise exc
            retries -= 1
            time.sleep(0.5)


@app.route('/')
def hello():
    count = get_hit_count()
    return 'Hello World! I have been seen {} times.\n'.format(count)

if __name__ == "__main__":
    app.run(host="0.0.0.0", debug=True)

Since I keep getting the Name error so I can’t access the local host. Can someone help me with this?
Thank you

`


(Fasmat) #2

What you created is a small python application. You cannot start it with docker-compose up. I suggest you continue the tutorial further and follow the instructions, as the actual docker compose file is created in step 3 and you can call docker-compose up at step 4