我正在尝试在一个码头化的快递应用程序中通过一个chrome实例获得灯塔分数,但得到了:
flare_backend | Error: connect ECONNREFUSED 127.0.0.1:9222
flare_backend | at __node_internal_captureLargerStackTrace (node:internal/errors:484:5)
flare_backend | at __node_internal_exceptionWithHostPort (node:internal/errors:662:12)
flare_backend | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) {
flare_backend | errno: -111,
flare_backend | code: 'ECONNREFUSED',
flare_backend | syscall: 'connect',
flare_backend | address: '127.0.0.1',
flare_backend | port: 9222
flare_backend | }
我基本上有两种服务:
class TestService {
async launchChrome () {
return await launch({
chromeFlags: ["--headless", "--no-sandbox", "--disable-gpu"],
port: 9222
});
}
async runLighthouse (url: string, chrome: LaunchedChrome, config: unknown) {
return await lighthouse(url, { port: chrome.port }, config);
}
}
async getTest () {
const chrome = await TestService.launchChrome();
console.log(chrome.port);
const lighthouse = await TestService.runLighthouse(
"https://www.google.com",
chrome,
{ extends: "lighthouse:default" }
);
return lighthouse;
}
我的后端Dockerfile和docker compose文件如下所示:
ARG NODE_VERSION="18.12.1"
ARG ALPINE_VERSION="3.17"
FROM --platform=linux/amd64 node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS base
WORKDIR /home/flare
RUN chown -R node:node /home/flare
RUN apk update && apk upgrade && \
apk add --no-cache chromium && \
rm -rf /var/cache/apk/*
ENV CHROME_BIN=/usr/bin/chromium-browser
COPY --chown=node:node package*.json ./
COPY --chown=node:node prisma ./prisma/
RUN npm install && npm cache clean --force
RUN npx prisma generate
COPY --chown=node:node . .
EXPOSE 8080
USER node
version: '3.9'
services:
postgres:
container_name: flare_postgres
image: postgres:15.1-alpine
restart: unless-stopped
volumes:
- ./backend/sql:/var/lib/postgresql/data
env_file:
- ./backend/.env
ports:
- 5432:5432
networks:
- flare_network
redis:
container_name: flare_redis
image: redis:7.0.5-alpine
restart: unless-stopped
ports:
- 6379:6379
networks:
- flare_network
nginx:
container_name: flare_nginx
build: ./backend/nginx
restart: unless-stopped
ports:
- 80:80
- 443:443
depends_on:
- backend
- frontend
networks:
- flare_network
prisma:
container_name: flare_prisma
command: sh -c "prisma migrate deploy && prisma studio"
build: ./backend/prisma
restart: unless-stopped
ports:
- 5555:5555
env_file:
- ./backend/.env
depends_on:
- postgres
networks:
- flare_network
backend:
container_name: flare_backend
command: sh -c "npm install && npm run dev"
build: ./backend
volumes:
- ./backend:/home/flare
- /home/flare/node_modules
working_dir: /home/flare
restart: unless-stopped
depends_on:
- postgres
- redis
ports:
- 8080:8080
networks:
- flare_network
frontend:
container_name: flare_frontend
command: sh -c "npm install && npm run dev"
build: ./frontend
volumes:
- ./frontend:/home/flare
- /home/flare/node_modules
working_dir: /home/flare
restart: unless-stopped
depends_on:
- backend
ports:
- 3000:3000
- 24678:24678
networks:
- flare_network
networks:
flare_network:
driver: bridge
我试图更改一些配置等,但无法解决问题。当我尝试在本地运行此应用程序时,它运行时没有问题,但在码头化环境中没有问题。我怀疑这可能是网络问题,但也不应该是真正的问题,因为express应用程序和chrome实例位于同一个容器中。这里可能有什么问题?