nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.92k stars 7.55k forks source link

use ConfigService connect mysql is not running in docker #10149

Closed ghost closed 2 years ago

ghost commented 2 years ago

Is there an existing issue for this?

Current behavior

this is my app.module.ts connect mysql

截屏2022-08-19 下午7 40 40

Minimum reproduction code

https://stackblitz.com/edit/nestjs-typescript-starter-ptvjje?file=src/app.module.ts

Steps to reproduce

docker build -t test-cloud .
docker run -p3000:3000 --name=test-docker test-cloud

Expected behavior

this is my dockerfile

####################
# build development
####################
FROM node:18.0.0-alpine3.15 As development

WORKDIR /usr/src/app

COPY --chown=test_user:test_user package*.json ./

RUN npm ci

# 构建开发-捆绑应用资源
COPY --chown=test_user:test_user . .

USER test_user

####################
# build production
####################

FROM node:18.0.0-alpine3.15 As build

WORKDIR /usr/src/app

COPY --chown=test_user:test_user package*.json ./

COPY --chown=test_user:test_user --from=development /usr/src/app/node_modules ./node_modules

COPY --chown=test_user:test_user . .

RUN npm run build

ENV NODE_ENV production

RUN npm ci --only=production && npm cache clean --force

USER test_user

####################
# production
####################

FROM node:18.0.0-alpine3.15 As production

WORKDIR /usr/src/app

COPY --chown=test_user:test_user --from=build /usr/src/app/node_modules ./node_modules
COPY --chown=test_user:test_user --from=build /usr/src/app/dist ./dist

CMD ["node", "dist/main.js"]

Package

Other package

No response

NestJS version

9.0.0

Packages versions

{
  "name": "test",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "NODE_ENV=development nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "NODE_ENV=production node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@liaoliaots/nestjs-redis": "^9.0.0",
    "@nestjs/common": "^9.0.2",
    "@nestjs/config": "^2.2.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/microservices": "^9.0.0",
    "@nestjs/platform-express": "9.0.0",
    "@nestjs/platform-socket.io": "^9.0.5",
    "@nestjs/swagger": "^6.0.2",
    "@nestjs/typeorm": "^9.0.0",
    "@nestjs/websockets": "^9.0.5",
    "bulma": "^0.9.4",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.13.2",
    "crypto-js": "^4.0.0",
    "hbs": "^4.2.0",
    "ioredis": "^5.2.1",
    "moment": "^2.29.3",
    "mysql2": "^2.3.3",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0",
    "swagger-ui-express": "^4.4.0",
    "swiper": "^6.5.1",
    "typeorm": "^0.3.7"
  },
  "devDependencies": {
    "@nestjs/cli": "^9.0.0",
    "@nestjs/schematics": "^9.0.0",
    "@nestjs/testing": "^9.0.0",
    "@types/crypto-js": "^4.1.1",
    "@types/express": "^4.17.13",
    "@types/hbs": "^4.0.1",
    "@types/jest": "28.1.4",
    "@types/multer": "^1.4.7",
    "@types/node": "^16.0.0",
    "@types/supertest": "^2.0.11",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.0.0",
    "eslint": "^8.0.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "jest": "^28.1.2",
    "prettier": "^2.3.2",
    "supertest": "^6.1.3",
    "ts-jest": "^28.0.5",
    "ts-loader": "^9.2.3",
    "ts-node": "^10.0.0",
    "tsconfig-paths": "^4.0.0",
    "typescript": "^4.3.5"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

Node.js version

18.0.0

In which operating systems have you tested?

Other

No response

micalevisk commented 2 years ago

Here's a Dockerfile that I've been using so far: https://gist.github.com/micalevisk/9ee47135b22f284dd73de6ea6d5aa864


Please, use our Discord for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.

ghost commented 2 years ago

这是我迄今为止一直在使用的 Dockerfile:https ://gist.github.com/micalevisk/9ee47135b22f284dd73de6ea6d5aa864

请使用我们的Discord解决此类问题。我们正在使用 GitHub 来跟踪错误、功能请求和潜在的改进。

my docker can running,itis ok,just use ConfigService is not running in docker

jmcdo29 commented 2 years ago

Please use our Discord channel (Support). We are using GitHub to track Bug Reports, Feature Requests, and Regressions.