Skip to content

Instantly share code, notes, and snippets.

@duwaljyoti
Last active November 18, 2018 08:00
Show Gist options
  • Save duwaljyoti/0f9c8d5697a685107949302443b76c9e to your computer and use it in GitHub Desktop.
Save duwaljyoti/0f9c8d5697a685107949302443b76c9e to your computer and use it in GitHub Desktop.
I was following this one..
https://docs.docker.com/get-started/part2/#introduction
=============================================
Dockerfile
# Use an official python runtime as a parent image.
FROM python:2.7-slim
# set the working directory to /app
WORKDIR /app
# copy everything from the current folder to app.
COPY . /app
# install all the dependencies mentioned in the requirements txt.
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# expose the port 80
EXPOSE 80
#defined the environment name as world.
ENV NAME world
# run the app.py when the container launches
CMD [ "python", "app.py" ]
# Set proxy server, replace host:port with values for your servers
ENV http_proxy host:port
ENV https_proxy host:port
===========================================
requirements.txt
Flask
Redis
===========================================
python.py
from flask import flask
from redis import Redis, RedisError
import os
import socket
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)
app = Flask(__name__)
@app.route("/")
def thello44():
try:
visits = redis.incr("counter")
except RedisError:
visits = "<i>cannot connect to Redis, counter disabled</i>"
html = "Hello from herer"
return html;
if __name__ == "__main__"
app.run(host='0.0.0.0', port=80)
============================================
everytime i run
docker run -p 4000:80 hellopython
i am getting issue saying
File "app.py", line 11
def hello()
^
SyntaxError: invalid syntax
things i have tried.
1) delete all containers.
2) restart docker.
what i didnot understand was.
while i am trying to "docker run -p 4000:80 hellopython" its loading from old file instead of newly created method.
notice the name of the method.its showing error in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment