我一直在尝试设置一个容器来运行带有瓶子框架的应用程序。阅读我能找到的所有内容,但即使这样我也做不到。这是我所做的:
Dockerfile:
# Use an official Python runtime as a parent image
FROM python:2.7
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 8080
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
应用程序.py:
import os
from bottle import route, run, template
@route('/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
run(host='localhost', port=8080)
要求.txt
bottle
通过运行命令docker build -t testapp
,我创建了容器。
然后通过运行命令docker run -p 8080:8080 testapp
我得到这个终端输出:
Bottle v0.12.13 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
但是当我去localhost:8080/testing
我得到localhost refused connection
。
谁能指出我正确的方向?