docker - 错误:找不到模块“winston”

时间:2021-03-29 09:07:10

标签: javascript node.js docker amazon-ec2 docker-compose

背景
我正在使用 EC2 实例来创建 docker 容器。

问题
当我运行 docker-compose up -d --build 时,所有容器都成功启动。
但是当我为 docker logs <container id> 容器运行 test-web 时,显示错误。

Error: Cannot find module 'winston'

我做了什么
我已经在本地环境中尝试过相同的命令,但它运行成功,所以我怀疑是 docker 问题。

我也尝试将图像转换为 sh,但 winston 模块存在于 node_modules 中。

Dockerfile

FROM node:lts-alpine

RUN npm install --global sequelize-cli nodemon

WORKDIR /server

COPY package*.json ./

RUN npm install

COPY . . 

EXPOSE 3030

CMD ["npm", "run", "dev"]

docker-compose.yml

version: '2.1'

services:
  test-db:
    image: mysql:5.7
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=true
      - MYSQL_USER=admin
      - MYSQL_PASSWORD=12345
      - MYSQL_DATABASE=test
    volumes:
      - ./db-data:/var/lib/mysql
    ports:
      - 3306:3306
  test-web:
    environment:
      - NODE_ENV=local
      #- DEBUG=*
      - PORT=3030
    build: .
    command: >
      ./wait-for-db-redis.sh test-db npm run dev
    volumes:
      - ./:/server
    ports:
      - "3030:3030"
    depends_on:
      - test-db

.dockerignore

node_modules
npm-debug.log

package.json

{
  "name": "docker-server",
  "description": "",
  "version": "0.0.0",
  "homepage": "",
  "private": true,
  "main": "src",
  "keywords": [
    "feathers"
  ],
  "author": {
    "name": "hello",
    "email": "hello@example.com"
  },
  "contributors": [],
  "bugs": {},
  "directories": {
    "lib": "src",
    "test": "test/",
    "config": "config/"
  },
  "engines": {
    "node": "^13.0.0",
    "npm": ">= 3.0.0"
  },
  "scripts": {
    "test": "npm run lint && npm run mocha",
    "lint": "eslint src/. test/. --config .eslintrc.json --fix",
    "dev": "nodemon --legacy-watch src/",
    "start": "node src/",
  },
  "standard": {
    "env": [
      "mocha"
    ],
    "ignore": []
  },
  "dependencies": {
    "@feathersjs/authentication": "^4.5.11",
    "@feathersjs/authentication-local": "^4.5.11",
    "@feathersjs/authentication-oauth": "^4.5.11",
    "@feathersjs/configuration": "^4.5.11",
    "@feathersjs/errors": "^4.5.11",
    "@feathersjs/express": "^4.5.11",
    "@feathersjs/feathers": "^4.5.11",
    "@feathersjs/socketio": "^4.5.11",
    "@feathersjs/transport-commons": "^4.5.11",
    "aws-sdk": "^2.868.0",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "express-winston": "^4.1.0",
    "feathers-hooks-common": "^5.0.5",
    "feathers-logger": "^0.3.2",
    "feathers-permissions": "^2.1.4",
    "feathers-sequelize": "^6.2.0",
    "helmet": "^4.4.1",
    "sequelize": "^6.5.1",
    "serve-favicon": "^2.5.0",
    "uuid": "^3.4.0",
    "winston": "^3.3.3",
    "winston-dynamodb": "^0.3.1"
  },
  "devDependencies": {
    "axios": "^0.21.1",
    "eslint": "^7.22.0",
    "mocha": "^8.3.2",
    "nodemon": "^2.0.7"
  }
}

0 个答案:

没有答案