parent
ee8bdc2fef
commit
aa2059a38c
35 changed files with 246 additions and 19 deletions
@ -0,0 +1,8 @@ |
||||
# 将 image 文件继承与官方的3.7版本的Python |
||||
FROM python:3.7 |
||||
# 将当前目录下的所有文件(除了 .dockerignore 排除的路径),都拷贝进 image 文件的 /app 目录。 |
||||
COPY . /app |
||||
# 指定接下来的工作路径为 /app |
||||
WORKDIR /app |
||||
# 在 /app 目录下,运行 python 文件 |
||||
CMD python3 hello.py |
@ -0,0 +1 @@ |
||||
print('Hello World') |
@ -0,0 +1,4 @@ |
||||
FROM python:3.7 |
||||
COPY ./pyramid.py /pyramid.py |
||||
ENTRYPOINT ["python3", "pyramid.py"] |
||||
CMD ["5"] # 指定参数时会被覆盖 |
@ -0,0 +1,11 @@ |
||||
import sys |
||||
|
||||
def print_pyramid(level: int): |
||||
for i in range(level): |
||||
new_line_str = '' |
||||
new_line_str += ' ' * (level - 1 - i) |
||||
new_line_str += '*' * ((i+1) * 2 - 1) |
||||
print(new_line_str) |
||||
|
||||
input_level = int(sys.argv[1]) |
||||
print_pyramid(input_level) |
@ -0,0 +1,6 @@ |
||||
FROM python:3.7 |
||||
COPY . /app |
||||
WORKDIR /app |
||||
RUN ["pip3", "install", "-r", "requirements.txt"] |
||||
EXPOSE 3000 |
||||
CMD ["python3", "server.py"] |
@ -0,0 +1,2 @@ |
||||
flask==2.1.0 |
||||
flask-cors==3.0.8 |
@ -0,0 +1,17 @@ |
||||
from flask import Flask, render_template |
||||
import json |
||||
|
||||
app = Flask(__name__) |
||||
|
||||
@app.route('/book') |
||||
def json_file(): |
||||
file = open('volume_data/book.json') |
||||
json_data = json.load(file) |
||||
return json_data |
||||
|
||||
@app.route('/') |
||||
def home(): |
||||
return render_template('index.html') |
||||
|
||||
if __name__ == '__main__': |
||||
app.run(host='0.0.0.0', port=3000) |
@ -0,0 +1,17 @@ |
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<title>Sample Book Info</title> |
||||
</head> |
||||
<body> |
||||
<h1>Volume Sample Book</h1> |
||||
<div id='content-info'></div> |
||||
<script> |
||||
fetch('./book') |
||||
.then(response => response.json()) |
||||
.then(data => { |
||||
document.querySelector('#content-info').innerText = data.title |
||||
}) |
||||
</script> |
||||
</body> |
||||
</html> |
@ -0,0 +1,3 @@ |
||||
{ |
||||
"title": "The Book Title" |
||||
} |
@ -0,0 +1,6 @@ |
||||
FROM python:3.7 |
||||
COPY . /app |
||||
WORKDIR /app |
||||
RUN ["pip3", "install", "-r", "requirements.txt"] |
||||
EXPOSE 5000 |
||||
CMD ["python3", "server.py"] |
@ -0,0 +1,5 @@ |
||||
{ |
||||
"title": "Book Title", |
||||
"description": "Description", |
||||
"link": "turingplanet.org" |
||||
} |
@ -0,0 +1,2 @@ |
||||
flask==2.1.0 |
||||
flask-cors==3.0.8 |
@ -0,0 +1,15 @@ |
||||
from flask import Flask, render_template |
||||
from flask_cors import CORS # need to mention |
||||
import json |
||||
|
||||
app = Flask(__name__) |
||||
CORS(app) |
||||
|
||||
@app.route('/book') |
||||
def json_file(): |
||||
file = open('./book.json') |
||||
json_data = json.load(file) |
||||
return json_data |
||||
|
||||
if __name__ == '__main__': |
||||
app.run(host='0.0.0.0', port=5000) |
@ -0,0 +1,6 @@ |
||||
FROM python:3.7 |
||||
COPY . /app |
||||
WORKDIR /app |
||||
RUN ["pip3", "install", "-r", "requirements.txt"] |
||||
EXPOSE 3000 |
||||
ENTRYPOINT ["python3", "server.py"] |
@ -0,0 +1 @@ |
||||
flask==2.1.0 |
@ -0,0 +1,10 @@ |
||||
from flask import Flask, render_template |
||||
|
||||
app = Flask(__name__) |
||||
|
||||
@app.route('/') |
||||
def home(): |
||||
return render_template('index.html') |
||||
|
||||
if __name__ == '__main__': |
||||
app.run(host='0.0.0.0', port=3000) |
@ -0,0 +1,16 @@ |
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<title>Sample Book Info</title> |
||||
</head> |
||||
<body> |
||||
<h1>Web App Sample Book</h1> |
||||
<div id='content-info'></div> |
||||
<script> |
||||
fetch('http://192.168.153.131:5000/book') |
||||
.then(response => response.json()) |
||||
.then(data => { document.querySelector('#content-info').innerText = data.title |
||||
}) |
||||
</script> |
||||
</body> |
||||
</html> |
@ -0,0 +1,6 @@ |
||||
FROM python:3.7 |
||||
COPY . /app |
||||
WORKDIR /app |
||||
RUN ["pip3", "install", "-r", "requirements.txt"] |
||||
EXPOSE 5000 |
||||
CMD ["python3", "server.py"] |
@ -0,0 +1,5 @@ |
||||
{ |
||||
"title": "Title_1", |
||||
"description": "Description", |
||||
"link": "turingplanet.org" |
||||
} |
@ -0,0 +1,2 @@ |
||||
flask==2.1.0 |
||||
flask-cors==3.0.8 |
@ -0,0 +1,15 @@ |
||||
from flask import Flask, render_template |
||||
from flask_cors import CORS # need to mention |
||||
import json |
||||
|
||||
app = Flask(__name__) |
||||
CORS(app) |
||||
|
||||
@app.route('/book') |
||||
def json_file(): |
||||
file = open('./book.json') |
||||
json_data = json.load(file) |
||||
return json_data |
||||
|
||||
if __name__ == '__main__': |
||||
app.run(host='0.0.0.0', port=5000) |
@ -0,0 +1,15 @@ |
||||
version: "3.9" |
||||
|
||||
services: |
||||
# 当前目录是docker-compose.yml所在文件夹 |
||||
backend: |
||||
build: ./backend # 第一个项目Dockerfile所在文件夹 |
||||
ports: |
||||
- "5000:5000" # 本地端口和容器内端口的映射 |
||||
volumes: |
||||
- ./backend:/app # 将backend目录和容器内的/app目录绑定 |
||||
|
||||
frontend: |
||||
build: ./frontend # 第二个项目Dockerfile所在文件夹 |
||||
ports: |
||||
- "3000:3000" |
@ -0,0 +1,6 @@ |
||||
FROM python:3.7 |
||||
COPY . /app |
||||
WORKDIR /app |
||||
RUN ["pip3", "install", "-r", "requirements.txt"] |
||||
EXPOSE 3000 |
||||
ENTRYPOINT ["python3", "server.py"] |
@ -0,0 +1 @@ |
||||
flask==2.1.0 |
@ -0,0 +1,10 @@ |
||||
from flask import Flask, render_template |
||||
|
||||
app = Flask(__name__) |
||||
|
||||
@app.route('/') |
||||
def home(): |
||||
return render_template('index.html') |
||||
|
||||
if __name__ == '__main__': |
||||
app.run(host='0.0.0.0', port=3000) |
@ -0,0 +1,16 @@ |
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<title>Sample Book Info</title> |
||||
</head> |
||||
<body> |
||||
<h1>Web App Sample Book</h1> |
||||
<div id='content-info'></div> |
||||
<script> |
||||
fetch('http://192.168.153.131:5000/book') |
||||
.then(response => response.json()) |
||||
.then(data => { document.querySelector('#content-info').innerText = data.title |
||||
}) |
||||
</script> |
||||
</body> |
||||
</html> |
@ -0,0 +1,6 @@ |
||||
FROM python:3.7 |
||||
COPY . /app |
||||
WORKDIR /app |
||||
RUN ["pip3", "install", "-r", "requirements.txt"] |
||||
EXPOSE 5000 |
||||
CMD ["python3", "server.py"] |
@ -0,0 +1,2 @@ |
||||
flask==2.1.0 |
||||
redis==3.5.3 |
@ -0,0 +1,16 @@ |
||||
from flask import Flask, render_template |
||||
import redis |
||||
import os |
||||
REDIS_HOST = os.environ.get('REDIS_HOST', '0.0.0.0') |
||||
|
||||
app = Flask(__name__) |
||||
cache = redis.Redis(host = REDIS_HOST, port = 6379, db = 0) |
||||
cache.set('hits', 0) |
||||
|
||||
@app.route('/') |
||||
def get_data(): |
||||
hit_num = cache.incr('hits') |
||||
return f'I have been seen {hit_num} times.\n' |
||||
|
||||
if __name__ == '__main__': |
||||
app.run(host='0.0.0.0', port=5000) |
@ -0,0 +1,14 @@ |
||||
version: "3.9" |
||||
|
||||
services: |
||||
|
||||
redis-server: |
||||
image: "redis" |
||||
|
||||
backend: |
||||
environment: |
||||
- REDIS_HOST=redis-server |
||||
build: ./backend |
||||
ports: |
||||
- "5000:5000" |
||||
|
@ -1,8 +0,0 @@ |
||||
{ |
||||
"folders": [ |
||||
{ |
||||
"path": "." |
||||
} |
||||
], |
||||
"settings": {} |
||||
} |
@ -1,8 +0,0 @@ |
||||
# 将image文件继承与官方的3.8版本的Python |
||||
FROM python:3.8 |
||||
# 将当前目录下的所有文件(除了.dockerignore排除的路径),都拷贝进image文件的/app目录。 |
||||
COPY . /app |
||||
# 指定接下来的工作路径为/app |
||||
WORKDIR /app |
||||
# 在/app目录下,运行python文件 |
||||
CMD python3 hello.py |
@ -1 +0,0 @@ |
||||
print("hello world") |
Loading…
Reference in new issue