关于mongodb:Docker-compose depend_on

Docker-compose depend_on

我有一个MongoDB服务和一个使用Docker Compose运行的测试服务:

1
2
3
4
5
6
7
8
9
10
services:  
  mongo:
    image: myrepo/mongo
    ports:
      -"27017:27017"
  test:
    depends_on:
      - mongo
    image: myrepo/elixir-tests
    command: sh start.sh

在start.sh脚本中,我尝试运行:

1
mongo 172.20.0.10:27017/wc-app-sandbox --eval"printjson(....))"

但我得到以下错误:

1
start.sh: 10: start.sh: mongo: not found

我的问题是:为什么会出错-depends-on属性是否假定自动包含服务依赖项?如前所述:

depends_on

Express dependency between services, which has two effects:

docker-compose up will start services in dependency order. In the
following example, db and redis will be started before web.
docker-compose up SERVICE will automatically include SERVICE’s
dependencies. In the following example, docker-compose up web will
also create and start db and redis.


这个错误并不意味着"我找不到到到Mongo容器的路由",它意味着"我找不到mongo执行bin"。可能图像myrepo/elixir-tests不包含mongo-client。尝试将它安装到容器中。

Mongo连接字符串应该类似于mongo mongo:27017/wc-app-sandbox --eval"printjson(....))"