Docker原因:连接EConRefuse0.0.0.0:80

Docker原因:连接EConRefuse0.0.0.0:80,docker,docker-compose,nuxt.js,Docker,Docker Compose,Nuxt.js,我在docker容器中运行了一个nuxtjs应用程序,我试图使用nuxt应用程序上的localhost连接到端点,但不幸的是,我得到了以下结果 error请求发送到http://0.0.0.0/api/articles 失败,原因:连接ECONREFUSSED 0.0.0.0:80 我正在尝试在nuxt配置中进行一次获取,以从getCMS生成一个站点地图 下面是获取的一个片段 sitemap: { hostname: `${process.env.BASE_URL}`, gzip

我在docker容器中运行了一个nuxtjs应用程序,我试图使用nuxt应用程序上的localhost连接到端点,但不幸的是,我得到了以下结果
error请求发送到http://0.0.0.0/api/articles 失败,原因:连接ECONREFUSSED 0.0.0.0:80

我正在尝试在nuxt配置中进行一次获取,以从getCMS生成一个站点地图

下面是获取的一个片段

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组件

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


http连接的默认端口是80,应用程序侦听5000。因此,当您尝试连接到0.0.0.0:80时,如果没有任何内容正在侦听,则连接将被拒绝。

您是否尝试在浏览器上访问
localhost:5000

即使端口80已暴露,问题仍然存在我可以访问该应用程序,但是应用程序无法在容器中执行提取,因为它在应用程序中找不到。您的API是NuxtJS中的expressJS?如果连接中间件作为端点公开,则应用程序在没有docker的情况下工作。它试图让应用程序在dockerYou不应该使用localhost。。它不会在初始服务器负载下工作。您应该使用私有IP服务器,就像192.168.1.1/api/I不打算使用确切的192.168.1.1/api/。。您应该知道确切的私有IP,或者您需要将该应用程序容器化,以便我们可以使用容器名称与之通信,如<代码>本地主机
将无法正常工作