Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Docker compose docker编写成功,但服务器在请求时不响应_Docker Compose_No Response - Fatal编程技术网

Docker compose docker编写成功,但服务器在请求时不响应

Docker compose docker编写成功,但服务器在请求时不响应,docker-compose,no-response,Docker Compose,No Response,我已经构建了一个RESTful API web服务,使用Flask框架,Redis作为主数据库,MongoDB作为备份存储,Celery作为任务队列,在后台将数据存储到MongoDB中 然后,我使用docker compose将我的应用程序dockerize。这是我的docker compose.yml: version: '3' services: web: build: . ports: - "5000:5000" volumes: -

我已经构建了一个RESTful API web服务,使用Flask框架,Redis作为主数据库,MongoDB作为备份存储,Celery作为任务队列,在后台将数据存储到MongoDB中

然后,我使用docker compose将我的应用程序dockerize。这是我的
docker compose.yml

version: '3'

services:
  web:
    build: .
    ports:
      - "5000:5000"
    volumes:
      - .:/app
  redis:
    image: "redis:alpine"
    ports:
      - "6379:6379"
  mongo:
    image: "mongo:3.6.5"
    ports:
      - "27017:27017"
    environment:
      MONGO_INITDB_DATABASE: syncapp
这是我的
Dockerfile

# base image
FROM python:3.5-alpine
MAINTAINER xhoix <145giakhang@gmail.com>

# copy just the requirements.txt first to leverage Docker cache
# install all dependencies for Python app
COPY ./requirements.txt /app/requirements.txt

WORKDIR /app

# install dependencies in requirements.txt
RUN pip install -r requirements.txt

# copy all content to work directory /app
COPY . /app

# specify the port number the container should expose
EXPOSE 5000

# run the application
CMD ["python", "/app/app.py"]
#基本图像
来自python:3.5-1
维护器xhoix
#首先只复制requirements.txt以利用Docker缓存
#安装Python应用程序的所有依赖项
复制./requirements.txt/app/requirements.txt
WORKDIR/app
#在requirements.txt中安装依赖项
运行pip安装-r requirements.txt
#将所有内容复制到工作目录/应用程序
抄袭/应用程序
#指定容器应公开的端口号
曝光5000
#运行应用程序
CMD[“python”,“/app/app.py”]
运行命令
docker compose up
后,应用服务器、Redis和Mongo服务器运行良好。但是当我使用Postmancurl调用API时,例如
http://127.0.0.1:5000/sync/api/v1.0/users
,它应该返回所有用户的JSON格式,但结果是
无法获得任何响应:连接到时出错http://127.0.0.1:5000/sync/api/v1.0/users.

我不知道为什么会这样。
谢谢你的帮助和建议

如果是Linux操作系统,则使用:

ifconfig-a

如果是Windows操作系统,则使用:

ipconfig/all

然后检查docker之类的虚拟化接口,并使用ipv4或inet

或者只需使用docker命令:

docker网络检查桥


然后在IPAM上使用网关ip

我找到了问题的原因:


经过一个小时的调试,我只需要将应用程序主机更改为
0.0.0.0
。可能在映射端口时,docker默认值将为0.0.0.0,因为当我运行命令
docker compose ps
时,每个容器的端口列都具有格式
0.0.0:->
。我不知道这是否是问题的原因,但我做到了,问题解决了

您是否尝试过向docker compose services添加
网络模式:主机
选项?