zoukankan      html  css  js  c++  java
  • [Docker] Linking Node.js and MongoDB Containers

    To do communcation between containers, we need to do link between containers.

    1. Run a container with a name

    docker run -d --name my-postgres postgres

    Give a name call 'my-postgres'

    2. Link to Running Container By Name:

    docker run -d -p 5000:5000 --link my-postgres:postgres danwahlin/aspnetcore

    We want to link 'my-postgres' to another container 'danwahlin/aspnetcore'. And you need to make sure, 'danwahlin/aspnetcore' is running.

    :postgres // is alias

    Example how to link MongoDB container to Node.

    We have a node.dockerfile:

    FROM node:latest
    
    MAINTAINER Dan Wahlin
    
    ENV NODE_ENV=development
    NEV PORT=3000
    
    COPY ./var/www
    WORKDIR /var/www
    
    RUN npm install
    
    EXPORT $PORT
    
    ENTRYPOINT ["npm", "start"]

    Build dockerfile:

    docker build -f node.dockerfile -t danwahlin/node .

    Here we point the file '-f node.dockerfile'

    Currently we have `node`, `mongodb` and `danwahlin/node` images.
     
    Start MongoDB container:
    docker run -d --name my-mongodb mongo
    Then start node container and link it to my-mongodb, give my-mongodb an alias as mongodb
    docker run -d -p 3000:3000 --link my-mongodb:mongodb danwahlin/node
    Start mongodb server in container:
    docker exec danwahlin/node node dbSeeder.js
    This will trigger `danwahlin/node` container and run `node dbSeeder.js` command.
  • 相关阅读:
    关于v$librarycache的几个字段含义
    nmon监控
    ORA-01841: (full) year must be between -4713 and +9999,
    MySql 5.7 新特性概览
    权限传递
    ORA-03135 防火墙超时设置断开db link 连接
    Oracle Profile使用详解(转)
    查看Oracle数据库SQL执行历史
    ALTER SEQUENCE 导致 REPLICAT 延时
    trace/trace2命令
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10649171.html
Copyright © 2011-2022 走看看