![]() ![]() Web_1 | * Running on (Press CTRL+C to quit) Step 3: Define services in a Compose fileĬreate a file called docker-compose.yml in your project directory and pasteĬreating network "composetest_default" with the default driverĪttaching to composetest_web_1, composetest_redis_1 Some editors may append this file extension automatically and which results in an error when you run the application.įor more information on how to write Dockerfiles, see theĪnd the Dockerfile reference. Set the default command for the container to flask run.Ĭheck that the Dockerfile has no file extension like.Add metadata to the image to describe that the container is listening on port 5000.Copy requirements.txt and install the Python dependencies.Set environment variables used by the flask command.Build an image starting with the Python 3.7 image.# syntax=docker/dockerfile:1 FROM python:3.7-alpine WORKDIR /code ENV FLASK_APP=app.py ENV FLASK_RUN_HOST=0.0.0.0 RUN apk add -no-cache gcc musl-dev linux-headersĬOPY requirements.txt requirements.txt RUN pip install -r requirements.txtĮXPOSE 5000 COPY. In aĬluster, this also helps handling momentary connection drops betweenĬreate another file called requirements.txt in your project directory and Service needs to be restarted anytime during the app’s lifetime. Online, but also makes the application more resilient if the Redis This is useful at startup while the application comes Loop lets us attempt our request multiple times if the redis service is Note the way the get_hit_count function is written. In this example, redis is the hostname of the redis container on theĪpplication’s network. route ( '/' ) def hello (): count = get_hit_count () return 'Hello World! I have been seen times. ConnectionError as exc : if retries = 0 : raise exc retries -= 1 time. Redis ( host = 'redis', port = 6379 ) def get_hit_count (): retries = 5 while True : try : return cache. Import time import redis from flask import Flask app = Flask ( _name_ ) cache = redis. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |