Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b0dce38

Browse files
use docker --link to link a two container(flask and redis) app
1 parent 0d046ef commit b0dce38

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

‎.vscode/settings.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"python.linting.pylintEnabled": false,
3+
"python.autoComplete.extraPaths": [
4+
"/usr/local/lib/python3.6/site-packages",
5+
"/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6"
6+
]
7+
}

‎README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,21 @@ use Dcokerfile to create a containerize python app
8080
> docker exec -it <container id> bash
8181
> ps aux
8282
```
83+
use Dcokerfile to create a containerize python app
84+
```
85+
> git clone -b v0.1 git@github.com:smalltide/dockerapp.git dockerapp
86+
> cd dockerapp
87+
> docker build -t dockerapp:v0.1 .
88+
> docker run -d -p 5000:5000 dockerapp:v0.1
89+
> docker exec -it <container id> bash
90+
> ps aux
91+
```
92+
use Dcokerfile to create a two container(flask and redis) app
93+
```
94+
> git clone -b v0.3 git@github.com:smalltide/dockerapp.git dockerapp0.3
95+
> cd dockerapp0.3
96+
> docker build -t dockerapp:v0.3 .
97+
> docker images
98+
> docker run -d --name redis redis:3.2.0
99+
> docker run -d -p 5000:5000 --link redis dockerapp:v0.3
100+
```

‎dockerapp0.3/Dockerfile‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3.5
2+
RUN pip install Flask==0.11.1 redis==2.10.5
3+
RUN useradd -ms /bin/bash admin
4+
USER admin
5+
WORKDIR /app
6+
COPY app /app
7+
CMD ["python", "app.py"]

‎dockerapp0.3/app/app.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from flask import Flask, request, render_template
2+
import redis
3+
4+
app = Flask(__name__)
5+
default_key = '1'
6+
cache = redis.StrictRedis(host='redis', port='6379', db=0)
7+
cache.set(default_key, 'one')
8+
9+
@app.route('/', methods=['GET', 'POST'])
10+
def mainpage():
11+
12+
key = default_key
13+
if 'key' in request.form:
14+
key = request.form['key']
15+
16+
if request.method == 'POST' and request.form['submit'] == 'save':
17+
cache.set(key, request.form['cache_value'])
18+
19+
cache_value = None
20+
if cache.get(key):
21+
cache_value = cache.get(key).decode('utf-8')
22+
23+
return render_template('index.html', key=key, cache_value=cache_value)
24+
25+
if __name__ == '__main__':
26+
app.run(host='0.0.0.0')
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<html>
2+
<head>
3+
<title>key value lookup service</title>
4+
</head>
5+
<body>
6+
<form method="POST">
7+
<input type="text" name="key" value={{ key }}>
8+
<input type="text" name="cache_value" value={{ cache_value }}>
9+
<input type="submit" name="submit" value="load">
10+
<input type="submit" name="submit" value="save">
11+
</form>
12+
</body>
13+
</html>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /