我使用Flask框架、Redis作为主数据库、MongoDB作为备份存储和Celery构建了一个 RESTful API Web 服务作为任务队列,在后台将数据存储到 MongoDB
然后我使用 docker -compose对我的应用程序进行 docker 化。这是我的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"]
运行 command 后docker-compose up
,app server、Redis 和 Mongo server 运行良好。但是当我使用Postman或curl调用 API 时,例如http://127.0.0.1:5000/sync/api/v1.0/users
应该返回所有用户的 JSON 格式,但结果是Could not get any response: There was an error connecting to http://127.0.0.1:5000/sync/api/v1.0/users.
我不知道为什么会这样。感谢您的任何帮助和建议!