[英]Docker compose:
For example, here is my project structure: 例如,这是我的项目结构:
project
|
+-- docker-compose.yml
|
+-- hq-backend
| +-- Dockerfile
| +-- .env.docker-compose
here is my docker compose file: 这是我的docker compose文件:
db:
container_name: hq-db
image: postgres:latest
ports:
- "5432:5432"
environment:
POSTGRES_USER: user_name
POSTGRES_PASSWORD: password
POSTGRES_DB: db_name
mongo:
container_name: hq-mongo
image: mongo:3.2.9
tty: true
stdin_open: true
ports:
- "27027:27027"
volumes:
- mongo:/data/db
hq-backend:
env_file:
- ../hq-backend/.env.docker_compose
build: ../hq-backend/
dockerfile: Dockerfile
ports:
- "8686:8686"
volumes:
- ".:/webapp"
links:
- db
- mongo
When I tried to run docker-compose up
. 当我尝试运行
docker-compose up
。 I always meet this exception at the end: 我总是在最后遇到这个例外:
ERROR: for hq-backend Cannot start service hq-backend: Cannot link to a non running container: /hq-mongo AS /project_hq-backend_1/mongo
错误:对于hq后端无法启动服务hq后端:无法链接到未运行的容器:/ hq-mongo AS / project_hq-backend_1 / mongo
Here is my environment file: 这是我的环境文件:
ENV=dev
DB_HOST=db
DB_ADDRESS=db
DB_PORT=5432
POSTGRES_DB=db_name
POSTGRES_USER=username
POSTGRES_PASSWORD=password
DB_MONGO_ADDRESS=mongo
DB_MONGO_PORT=27027
This problem is only with mongo service, not db service. 此问题仅与mongo服务有关,与db服务无关。 After that, if I tried to run
docker-compose up
again, no error found, but my hq-backend
will throw exception because cannot connect to mongo db. 之后,如果我尝试再次运行
docker-compose up
,没有发现错误,但是我的hq-backend
将抛出异常,因为无法连接到mongo db。 In other word, I just meet this problem when rebuild hq-backend
from scratch. 换句话说,当从头开始重建
hq-backend
时,我只是遇到了这个问题。
Please tell me about this problem. 请告诉我这个问题。
Remove tty and stdin_open options from docker-compose file. 从docker-compose文件中删除tty和stdin_open选项。 i suppose that it's messing with how docker-compose is handling containers.
我想这与docker-compose如何处理容器搞混了。 if You want to execute commands inside mongo container then after compose up just login into it using: docker exec -t -i hq-mongo /bin/bash
如果您想在mongo容器中执行命令,则在编写后只需使用以下命令登录:docker exec -t -i hq-mongo / bin / bash
By the way - You may consider to use docker-compose version 2 or 3 and depends_on instead of links https://docs.docker.com/compose/compose-file/compose-file-v2/ 顺便说一句-您可能会考虑使用docker-compose版本2或3和Depends_on而不是链接https://docs.docker.com/compose/compose-file/compose-file-v2/
Try adding depends_on
to hq-backend at the same level as links. 尝试在与链接相同的级别
depends_on
添加到hq-backend。 For example: 例如:
depends_on:
- mongo
- db
links:
- db
- mongo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.