“无法访问此站点”(非常简单的docker指令)

时间:2018-08-01 07:11:31

标签: docker flask

问题出在这里:当我打开浏览器并输入“ 172.17.0.2:5000”时,无法访问该网站。

我只是按照Simple Web Application README link的官方指示进行操作。打击脚本是其一系列命令。

2  apt-get update
3  apt-get install -y python
4  apt-get install python-pip
5  ls
6  cat > /opt/app.py
7  vim opt/app.py
8  vi opt/app.py
9  apt-get install vim
10  vim opt/app.py
11  cd opt
12  FLASK_APP=app.py flask run --host=0.0.0.0

这是我的app.py内容。

import os
from flask import Flask
app = Flask(__name__)

@app.route("/")
def main():
    return "Welcome!"

@app.route('/how are you')
def hello():
    return 'I am good, how about you?'

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8080)

当我运行flask应用程序时,它会显示

root@65d11b14d00b:/# FLASK_APP=opt/app.py flask run --host=0.0.0.0

 * Serving Flask app "opt/app.py"
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

要获取我的内部docker IP地址,请docker inspect

"Networks": {
    "bridge": {
        "IPAddress": "172.17.0.2",
        ...

我尝试更改app.py中的端口号,以及其他许多操作,但是没有一个起作用。


回复@Burhan,

➜  ~ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
ee543a9ce1cb        ubuntu              "bash"              6 minutes ago       Up 6 minutes                            elastic_hodgkin
➜  ~ docker run -d -p 5000:5000 ubuntu
28c1c29b7452e97adae3111632a0b67a320a2c0289034b4c517b015e1ca98c18
➜  ~ docker run -d -p 5000:5000 elastic_hodgkin
Unable to find image 'elastic_hodgkin:latest' locally
docker: Error response from daemon: pull access denied for elastic_hodgkin, repository does not exist or may require 'docker login'.
See 'docker run --help'.

似乎docker run -d -p 5000:5000 ubuntu有效。但是我仍然无法访问localhost:5000172.17.0.2:5000

0 个答案:

没有答案