Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
py-counter
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
docker101
py-counter
Commits
664ecf53
Commit
664ecf53
authored
5 years ago
by
Ahmad Anvari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Init
parents
master
No related merge requests found
Pipeline
#886
canceled with stages
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
0 deletions
+45
-0
Dockerfile
Dockerfile
+12
-0
app.py
app.py
+26
-0
requriements.txt
requriements.txt
+7
-0
No files found.
Dockerfile
0 → 100644
View file @
664ecf53
FROM
python:3.7
WORKDIR
/app
COPY
. /app
RUN
pip
install
-r
requriements.txt
EXPOSE
80
CMD
["python", "app.py"]
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app.py
0 → 100644
View file @
664ecf53
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
)
This diff is collapsed.
Click to expand it.
requriements.txt
0 → 100644
View file @
664ecf53
Click==7.0
Flask==1.1.1
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
redis==3.3.8
Werkzeug==0.15.5
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment