gpt4 book ai didi

node.js - Docker容器内部网络错误: connect ECONNREFUSED 127. 0.0.1:8002

转载 作者:太空宇宙 更新时间:2023-11-03 23:18:26 25 4
gpt4 key购买 nike

我正在构建一个在 docker 容器中运行的 Nodejs 应用程序并收到以下错误

NetworkingError: connect ECONNREFUSED 127.0.0.1:8000"

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

NetworkingError: write EPROTO 140494555330368:error:1408F10B:SSLroutines:ssl3_get_record:wrong version number:../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 时,它将完美工作。

请帮我解决这个问题。

最佳答案

在 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

关于node.js - Docker容器内部网络错误: connect ECONNREFUSED 127. 0.0.1:8002,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52465695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com