Docker 原因 : connect ECONNREFUSED 0. 0.0.0:80

标签 docker docker-compose nuxt.js

我有一个在 docker 容器中运行的 nuxtjs 应用程序,我正在尝试使用 nuxt 应用程序上的本地主机连接到端点,但不幸的是我得到以下信息 错误 RROR 请求到 http://0.0.0.0/api/articles 失败,原因:连接 ECONNREFUSED 0.0.0.0:80

我正在尝试在 nuxt 配置中进行抓取,以从 getcockpit cms 生成站点地图。

这是抓取的片段。

sitemap: {
    hostname: `${process.env.BASE_URL}`,
    gzip: true,
    routes: async () => {
      const articles = await fetch(`http://0.0.0.0/api/articles`, {
        method: 'post',
        body: JSON.stringify({
          filter: {
            Published: true
          }
        })
      })
        .then((res) => res.json())
        .then((values) => {
          const results = values.entries
          return results
            .filter((result) => result.url.length > 0)
            .map((result) => result.url)
        })
        .catch((err) => console.error(err))
      return articles
    }
  },

以及 Docker 文件的副本

FROM node:12.16.1-alpine

# create destination directory
RUN mkdir -p /usr/src/nuxt-app
WORKDIR /usr/src/nuxt-app

# update and install dependency
RUN apk update && apk upgrade
RUN apk add git

# copy the app, note .dockerignore
COPY . /usr/src/nuxt-app/
RUN npm ci

# build necessary, even if no static files are needed,
# since it builds the server as well
RUN npm run build

# expose 5000 on container
EXPOSE 5000    
RUN npm config set https-proxy 127.0.0.1:9000 

# set app serving to permissive / assigned
ENV NUXT_HOST=0.0.0.0
# set app port
ENV NUXT_PORT=5000
ENV HOST 0.0.0.0
ENV PORT 5000
ENV HTTP_PROXY http://docker.for.mac.localhost.internal:3128
ENV HTTPS_PROXY  https://docker.for.mac.localhost.internal:3128
ENV FTP_PROXY ftp://docker.for.mac.localhost.internal:3128
ENV NO_PROXY  http://docker.for.mac.localhost.internal:3128


ENV BASE_URL=http://nuxt
ENV GET_ARTICLES_API_TOKEN=token
ENV GET_ARTICLES_URL=example.com
# start the app
CMD [ "npm", "start"]

当前的 Docker Compose

version: "2"
services:
  nuxt:
    build: .
    ports:
      - 5000:5000
    environment:
      ENV NUXT_HOST: 0.0.0.0
      ENV NUXT_PORT: 5000

最佳答案

你试过在你的浏览器上访问 localhost:5000 吗?

关于Docker 原因 : connect ECONNREFUSED 0. 0.0.0:80,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60879099/

相关文章:

docker - gcloud docker无法在Compute Engine VM上运行

docker - Docker无法找到文件

docker - Google Cloud Composer 与 Docker 上的 Airflow

docker - 将 docker 卷移动到不同的分区

docker - 使用 docker-compose 时如何修复容器的基本名称?

vue.js - 如何使用 vue v3 项目将 boostrap v5 (js + css) 导入 nuxt.js v2.14?

vue.js - 在不更改路由的情况下重新评估 Nuxt.js 中间件

docker compose 网络版本 3 – 除非使用公共(public) IP,否则容器无法互相看到?

docker - 如何将我的服务公开给内部 docker 网络?

vue.js - nuxt 为动态页面 nuxt.js 生成抛出错误