how to map database from couchdb container to another containers webapp in same docker-compose file

 ̄綄美尐妖づ 提交于 2019-12-24 15:53:14

问题


I am having one web application which is running with couchdb database. This coudb container has multiple databases from which web application need only one database. I am using docker compose to run it but web application didn't recognize database inside couchdb container by docker-compose.yml file as below

version: "2"
services:
    db:
      image: mysite/couch:latest
      ports:
       - "15984:5984"
      environment:
         DB_USER: admin
         DB_PASSWORD: password
         DB_NAME: db_new
    webapp:
      image: mysite/webapp:latest
      ports:
       - "3050:3000"
      links:
       - db
       - db:db_new

If I run docker manually as mentioned below it works fine

docker run --rm -e DB_URL=http://localip:15984/db_new -p 0.0.0.0:3050:3000

Any Ideas what I am missing in docker-compose file?


回答1:


After spending lots of time on docker-compose I got the solution as below

version: "2"
services:
    db:
      image: mysite/couch:latest
      ports:
       - "15984:5984"
    webapp:
      image: mysite/webapp:latest
      ports:
       - "3050:3000"
      links:
        - db
      environment:
         DB_URL: http://admin:password@db:5984/db_new


来源:https://stackoverflow.com/questions/37484726/how-to-map-database-from-couchdb-container-to-another-containers-webapp-in-same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!