2017-08-25 12 views
0

私はボトルフレームワークでアプリケーションを実行するためにコンテナを設定しようとしています。私がそれについて見つけることができるすべてを読んでください、しかし私はそれをすることはできません。ここに私がやったことだ:bottle.pyアプリケーションをビルドして実行できません

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"] 

app.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) 

requirements.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を取得します。

誰でも正しい方向に向けることができますか?

答えて

3

問題は、この行です:

run(host='localhost', port=8080) 

それはあなたがコードを実行しているコンテナinsdeは「localhost」のためにそれを公開しています。そして、あなたが​​にアクセスすることができる(あなたのドッカエンジンがローカルホストであるasuming)します

run(host='0.0.0.0', port=8080) 

:あなたがしたい場合は、コンテナの外部インターフェイスを取得するためのpythonライブラリnetifacesを使用することができますが、私はあなたのようなhostとして0.0.0.0を設定することをお勧め

編集:以前のコンテナがまだ8080/tcpでリッスンしている可能性があります。前の容器を先に取り出したり、止めたりする。

+0

これはRobertoさんに感謝しました! –

関連する問題