我在一辆独轮车上运行多个容器。这些容器使用两个不同的docker-compose
. 它们是 api 的副本,唯一的区别是它们使用不同的环境变量运行。同时,当一个容器启动,另一个从deploy_storage-api_1 exited with code 137
. 据我了解,内存有问题runtime
。但我不知道如何真正理解发生了什么。我试图在 中公开资源docker-compose
,但事实证明,没有swarm
. 告诉我如何解决这个问题?没有它可以完成swarm
吗?我还注意到另外 5-6 个容器在独轮车上旋转。
Dockerfile
FROM ubuntu:18.04 AS BUILD
RUN apt-get update && apt-get install make
RUN apt-get install -y python3.7 python3-pip
RUN python3.7 -m pip install --upgrade pip
RUN apt-get install -y git
COPY . /app
WORKDIR /app
RUN PIP=pip PYTHON=python3.7 make deps
CMD PIP=pip PYTHON=python3.7 make run
环境-1
MONGO_URI=mongodb+srv://xxx:yyy@a.b.c/bbb
PORT=5001
EVE_USER=aaa
EVE_PASSWORD=zzz
环境-2
MONGO_URI=mongodb+srv://ppp:lll@a.b.c/fff
PORT=5000
EVE_USER=www
EVE_PASSWORD=mmm
码头工人撰写-1
version: '2'
services:
storage-api:
restart: always
environment:
- ENV_FILE=.deploy/.envs/stage.env
build:
context: ..
dockerfile: .deploy/Dockerfile
ports:
- "5000:5000"
volumes:
- ..:/app
mem_limit: 10240m
码头工人撰写-2
version: '2'
services:
storage-api:
restart: always
environment:
- ENV_FILE=.deploy/.envs/prod.env
build:
context: ..
dockerfile: .deploy/Dockerfile
ports:
- "5001:5001"
volumes:
- ..:/app
mem_limit: 1024m
日志-1
eurvanov@grader-services-2:~/grader-storage$ sudo docker-compose -f .deploy/docker-compose.stage.yml up
Recreating deploy_storage-api_1 ...
Recreating deploy_storage-api_1 ... done
Attaching to deploy_storage-api_1
storage-api_1 | storage starting...
storage-api_1 | PYTHONPATH=. ENV_FILE=.deploy/.envs/stage.env
storage-api_1 |
storage-api_1 | PYTHONPATH=. ENV_FILE=.deploy/.envs/stage.env python3.7 app.py
storage-api_1 | 2019-10-21 18:55:55,083 INFO [root] [in app.py :<module> :17 ]: port: 5000
storage-api_1 |
storage-api_1 | * Serving Flask app "eve" (lazy loading)
storage-api_1 | * Environment: production
storage-api_1 | WARNING: This is a development server. Do not use it in a production deployment.
storage-api_1 | Use a production WSGI server instead.
storage-api_1 | * Debug mode: off
storage-api_1 | 2019-10-21 18:55:55,105 INFO [werkzeug] [in /usr/local/lib/python3.7/dist-packages/werkzeug/_internal.py:_log :122 ]: * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
日志-2
eurvanov@grader-services-2:~/grader-storage$ sudo docker-compose -f .deploy/docker-compose.prod.yml up
Recreating deploy_storage-api_1 ...
Recreating deploy_storage-api_1 ... done
Attaching to deploy_storage-api_1
storage-api_1 | storage starting...
storage-api_1 | PYTHONPATH=. ENV_FILE=.deploy/.envs/prod.env
storage-api_1 |
storage-api_1 | PYTHONPATH=. ENV_FILE=.deploy/.envs/prod.env python3.7 app.py
storage-api_1 | 2019-10-21 18:55:37,039 INFO [root] [in app.py :<module> :17 ]: port: 5001
storage-api_1 |
storage-api_1 | * Serving Flask app "eve" (lazy loading)
storage-api_1 | * Environment: production
storage-api_1 | WARNING: This is a development server. Do not use it in a production deployment.
storage-api_1 | Use a production WSGI server instead.
storage-api_1 | * Debug mode: off
storage-api_1 | 2019-10-21 18:55:37,061 INFO [werkzeug] [in /usr/local/lib/python3.7/dist-packages/werkzeug/_internal.py:_log :122 ]: * Running on http://0.0.0.0:5001/ (Press CTRL+C to quit)
deploy_storage-api_1 exited with code 137
eurvanov@grader-services-2:~/grader-storage$
解决方案非常简单。两个同名的容器可以互相杀死。同时,在一种情况下,他们互相残杀。在另一个,等价的,没有。为什么会发生这种情况,我还没有发现。这就是为什么我问了一个单独的问题。解决办法是这样的:取不同的名字,这样就没有交集了。