Docker容器内部NetworkingError:连接ECONNREFUSED 127.0.0.1:8002

时间:2018-09-23 11:34:37

标签: node.js docker docker-compose amazon-dynamodb aws-sdk

我正在构建一个在docker容器中运行的nodejs应用,并遇到以下错误

  

NetworkingError:连接ECONNREFUSED 127.0.0.1:8000“

如果我尝试使用 dynamodb-local:8000 ,那么它会给我以下错误

  

NetworkingError:写EPROTO   140494555330368:错误:1408F10B:SSL例程:ssl3_get_record:错误   版本号:../ deps / openssl / openssl / ssl / record / ssl3_record.c:252:

我正在使用以下 docker-compose.yml

        version: "3"

        services:
        node_app:
            build: .
            container_name: 'node_app'
            restart: 'always'
            command: 'npm run start:local'
            ports:
            - "3146:3146"
            links:
            - dynamodb-local
        dynamodb-local:
            container_name: 'dynamodb-local'
            build: dynamodb-local/
            restart: 'always'
            ports:
            - "8000:8000"

Node js docker配置如下, node_app

        FROM node:latest

        RUN mkdir -p /app/node_app

        WORKDIR /app/node_app


        # Install app dependencies
        COPY package.json /app/node_app
        #RUN npm cache clean --force && npm install
        RUN npm install


        # Bundle app source
        COPY . /app/node_app

        # Build the built version
        EXPOSE 3146
        #RUN npm run dev

        CMD ["npm", "start"]

Dynamo DB本地docker配置如下, dynamodb-local

        #
        # Dockerfile for DynamoDB Local
        #
        # https://aws.amazon.com/blogs/aws/dynamodb-local-for-desktop-development/
        #
        FROM openjdk:7-jre

        RUN mkdir -p /var/dynamodb_local
        RUN mkdir -p /var/dynamodb_picstgraph

        # Create working space
        WORKDIR /var/dynamodb_picstgraph

        # Default port for DynamoDB Local
        EXPOSE 8000

        # Get the package from Amazon
        RUN wget -O /tmp/dynamodb_local_latest https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz && \
            tar xfz /tmp/dynamodb_local_latest && \
            rm -f /tmp/dynamodb_local_latest

        # Default command for image
        ENTRYPOINT ["/usr/bin/java", "-Djava.library.path=.", "-jar", "DynamoDBLocal.jar", "-sharedDb", "-dbPath", "/var/dynamodb_local"]
        CMD ["-port", "8000"]

        # Add VOLUMEs to allow backup of config, logs and databases
        VOLUME ["/var/dynamodb_local", "/var/dynamodb_nodeapp"]

但是,当我尝试将外部docker容器连接到本地dynamodb时,它将完美运行。

请帮助我解决此问题。

1 个答案:

答案 0 :(得分:1)

在docker容器内,主机dynamodb-local:8000可以使用该数据库。

这可能是SSL问题,如果您已将端口用于其他应用程序,请检查您的apache配置。

在这种情况下,您可以按以下方式在另一个端口上使用链接发电机,

    #
    # Dockerfile for DynamoDB Local
    #
    # https://aws.amazon.com/blogs/aws/dynamodb-local-for-desktop-development/
    #
    FROM openjdk:7-jre

    RUN mkdir -p /var/dynamodb_local
    RUN mkdir -p /var/dynamodb_picstgraph

    # Create working space
    WORKDIR /var/dynamodb_picstgraph

    # Default port for DynamoDB Local
    EXPOSE 8004

    # Get the package from Amazon
    RUN wget -O /tmp/dynamodb_local_latest https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz && \
        tar xfz /tmp/dynamodb_local_latest && \
        rm -f /tmp/dynamodb_local_latest

    # Default command for image
    ENTRYPOINT ["/usr/bin/java", "-Djava.library.path=.", "-jar", "DynamoDBLocal.jar", "-sharedDb", "-dbPath", "/var/dynamodb_local"]
    CMD ["-port", "8004"]

    # Add VOLUMEs to allow backup of config, logs and databases
    VOLUME ["/var/dynamodb_local", "/var/dynamodb_nodeapp"]

现在在您的docker容器中,主机dynamodb-local:8004可以使用该数据库。