如何调用在Linux机器上部署为Docker Container的Rest-Endpoint

时间:2017-05-02 14:42:51

标签: node.js linux curl docker nodes

如果重复道歉: 我有一个docker容器,它是一个Node.js服务。我想从同一个linux机器测试该服务的端点。我正在使用curl命令测试端点我得到curl: (56) Recv failure: Connection reset by peer

这是我的Dockerfile

FROM ubuntu

ARG ENVIRONMENT
ARG PORT

RUN apt-get update -qq
RUN apt-get install -y build-essential nodejs npm nodejs-legacy vim

RUN mkdir /database_service
ADD . /database_service
WORKDIR /database_service

RUN npm install -g express
RUN npm install -g path
RUN npm cache clean


EXPOSE $PORT

ENTRYPOINT [ "node",  "server.js" ]
CMD [ $PORT, $ENVIRONMENT ]

这是我的配置文件:

module.exports = {
        database: {
            username: 'someusername',
            password: 'somepassword',
            host: '13.68.86.237',
            port: 27017,
            name: 'admin'   
        },
        "sandbox_config": {
            "commerce.api.endpoint":"sandbox_ep",
            "eurekaInstance":{
                    "instanceId":'10.71.9.40:database-service:'+process.env.PORT || 9200,
                    "hostName": 'database-service',
                    "app": 'database-service',
                    "ipAddr": '10.71.9.40',
                    "port": { '$': process.env.PORT || 9200, '@enabled': 'true' },
                    "securePort": { '$': 443, '@enabled': 'false' },
                    "dataCenterInfo": {
                        '@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
                         "name": 'MyOwn'
                    },
                    "homePageUrl": 'http://database-service:'+process.env.PORT || 9200+'/',
                    "statusPageUrl": 'http://database-service:'+process.env.PORT || 9200+'/info',
                    "healthCheckUrl": 'http://database-service:'+process.env.PORT || 9200+'/health',
                    "vipAddress": 'database-service',
                    "secureVipAddress": 'database-service',
                    "isCoordinatingDiscoveryServer": 'false',
                    "leaseInfo": { 
                        "renewalIntervalInSecs": 60000,
                        "durationInSecs": 60000,
                    }
            },
            "eurekaConfig":{
                 "host":'eureka-server',
                 "port":8761,
                 "servicePath":'/eureka/apps/'
             }
        }

};

请建议这里缺少什么或错误的命令。

Here is the Snap for error

1 个答案:

答案 0 :(得分:0)

如果您运行docker image inspect image_tag,您会看到在CMD指令中插入的变量在容器运行时才会被解析。

ARG说明

后添加此内容
ENV PORT $PORT
ENV ENVIRONMENT $ENVIRONMENT

确保在运行时可以使用默认环境变量