postgresql - docker compose 与网络,连接 ECONNREFUSED
问题描述
您好我有以下 docker 设置我有一个 postgres 图像和我的容器节点 alpine
我的码头文件:
#building code FROM node:lts-alpine
RUN mkdir -p /home/node/api/node_modules && chown -R node:node /home/node/api
WORKDIR /home/node/api
COPY ormconfig.json .env package.json yarn.* ./
USER node
RUN yarn
COPY --chown=node:node . .
EXPOSE 4000
CMD ["yarn", "dev"]
和我的码头工人撰写文件:
version: '3.7'
services:
ci-api:
build: .
container_name: ci-api
volumes:
- .:/home/node/api
- /home/node/api/node_modules
ports:
- '${SERVER_PORT}:${SERVER_PORT}'
depends_on:
- ci-postgres
networks:
- ci-network
ci-postgres:
image: postgres:12
container_name: ci-postgres
environment:
- ALLOW_EMPTY_PASSWORD=no
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASS}
- POSTGRES_DB=${DB_NAME}
volumes:
- ci-postgres-data:/data
networks:
- ci-network
volumes:
ci-postgres-data:
networks:
ci-network:
driver: bridge
我的环境文件:
SERVER_PORT=4000
DB_HOST=ci-postgres
DB_PORT=5432
DB_USER=spirit
DB_PASS=api
DB_NAME=db
我的配置:
{
"type": "postgres",
"host": "${DB_HOST}",
"port": 5432,
"username": "spirit",
"password": "emasa",
"database": "emasa_base",
"synchronize": true,
"logging": false,
"entities": ["dist/src/entity/**/*.js"],
"migrations": ["dist/src/migration/**/*.js"],
"subscribers": ["dist/src/subscriber/**/*.js"],
"cli": {
"entitiesDir": "dist/src/entity",
"migrationsDir": "dist/src/migration",
"subscribersDir": "dist/src/subscriber"
}
}
我的 package.json:
{
"name": "training",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon src/index.ts --exec ts-node",
"build": "tsc -b",
"lint": "eslint src/**/*.ts",
"format": "eslint src/**/*.ts --fix"
},
"devDependencies": {
"@types/express": "^4.17.6",
"@types/node": "^14.0.6",
"@typescript-eslint/eslint-plugin": "^3.0.2",
"@typescript-eslint/parser": "^3.0.2",
"eslint": "^7.1.0",
"eslint-config-node": "^4.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"prettier": "^2.0.5",
"ts-node": "^8.10.2",
"typescript": "^3.9.3"
},
"dependencies": {
"apollo-server": "^2.14.1",
"apollo-server-express": "^2.14.1",
"express": "^4.17.1",
"graphql": "^15.0.0",
"nodemon": "^2.0.4",
"reflect-metadata": "^0.1.13",
"type-graphql": "^1.0.0-rc.2",
"typeorm": "^0.2.25"
}
}
我得到这个错误:
错误发生意外错误:“ https://registry.yarnpkg.com/express/-/express-4.17.1.tgz : connect ECONNREFUSED 104.16.26.35:443”。
错误:服务“ci-api”构建失败:命令“/bin/sh -c yarn”返回非零代码:1