nodemon 不使用 docker 充值
Posted
技术标签:
【中文标题】nodemon 不使用 docker 充值【英文标题】:nodemon does not recharge with docker 【发布时间】:2019-01-02 06:09:50 【问题描述】:我正在尝试使用 docker 将 api 挂载到 js 节点,一切正常,但不幸的是,当我对文件进行更改时,docker 不更新文件并且 nodemon 不更新服务器,这迫使我总是重启docker-compose up --build
命令。
我的树:
|- api
|- src
|- app.js
|- index.js
|- routes.js
|- .dockerignore
|- .editorconfig
|- .env.example
|- .package.json
|- app
|- docker-compose.yml
我的 docker-compose.yml :
version: '3'
services:
api:
build: ./api
command: npm run dev
volumes:
- ./api:/app
ports:
- 3001:3000
restart: always
environment:
- "NODE_ENV=development"
# front:
# build: ./front
# volumes:
# - ./front:/usr/src/app
# ports:
# - 3000:3000
我在 /api 中的 dockerfile :
FROM node:10
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm install --only=production
# Bundle app source
COPY . .
EXPOSE 3000
CMD [ "npm", "run", "dev" ]
我的 package.json :
"name": "exampleApp",
"version": "1.0.0",
"description": "an example app",
"author": "Jean Bon <jeanbon@gmail.com>",
"license": "MIT",
"main": "dist/index.js",
"scripts":
"prestart": "npm run -s build",
"start": "node dist/index.js",
"dev": "nodemon src/index.js --exec \"node -r dotenv/config -r babel-register\"",
"clean": "rimraf dist",
"build": "npm run clean && mkdir -p dist && babel src -s -D -d dist",
"test": "jest --watch",
"lint": "esw -w src test"
,
"keywords": [
"express",
"babel",
"boilerplate",
"scaffold",
"es6",
"es2015",
"es2016",
"es2017",
"jest",
"eslint"
],
"dependencies":
"babel-cli": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"body-parser": "^1.18.2",
"express": "^4.16.2",
"pug": "^2.0.0-beta11",
"rimraf": "^2.6.2"
,
"devDependencies":
"babel-eslint": "^8.0.3",
"babel-jest": "^21.2.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-register": "^6.26.0",
"dotenv": "^4.0.0",
"eslint": "^4.12.1",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jest": "^21.3.2",
"eslint-watch": "^3.1.3",
"jest": "^21.2.1",
"nodemon": "^1.12.1",
"supertest": "^3.0.0"
,
"babel":
"presets": [
[
"env",
"targets":
"node": "current"
]
],
"plugins": [
"transform-object-rest-spread",
"transform-class-properties"
]
,
"eslintConfig":
"parser": "babel-eslint",
"plugins": [
"import",
"jest"
],
"parserOptions":
"ecmaVersion": 2017,
"sourceType": "module"
,
"env":
"node": true,
"jest": true
,
"extends": [
"eslint:recommended"
],
"rules":
"jest/no-focused-tests": 2,
"jest/no-identical-title": 2
,
"jest":
"testEnvironment": "node"
在我的终端中,nodemon 可以工作,但是当我进行修改时,没有任何动作:
docker-compose log picture
提前感谢您的帮助:)
【问题讨论】:
您要更改哪些文件以及如何更改它们? 我只是更改了 json 中的字符串(文件:routes.js),以便在邮递员上查看答案是否更改。 你解决了这个问题吗? 【参考方案1】:您必须在脚本中添加 --watch。试试这个:
nodemon --watch src/index.js --exec \"node -r dotenv/config -r babel-register\""
查看documentation 的更多信息,查看监控多个目录部分。
【讨论】:
【参考方案2】:尝试使用-L
标志运行nodemon:nodemon -L app.js
来自documentation
【讨论】:
以上是关于nodemon 不使用 docker 充值的主要内容,如果未能解决你的问题,请参考以下文章
Docker /bin/bash: nodemon: 找不到命令
Webstorm- Nodemon + Typescript + Docker - 调试器已连接但断点不起作用
为啥我使用 nodemon 和 ts-node 时节点检查器不启动?
Nodemon 在 Windows Docker 环境中不重启