简体   繁体   English

如何在我的 node.js 应用程序中将 nodemon 与 docker 一起使用?

[英]How do I use nodemon with docker in my node.js application?

I am new to Docker and coding.我是 Docker 和编码的新手。 I have already added it as dev-dependency but still I have to build the image every time I make a change to the code.我已经将它添加为开发依赖项,但每次更改代码时我仍然必须构建图像。 I have tried looking this up but have not found a solution that is suitable/working because I am using process.json file.我试过查找这个,但没有找到适合/工作的解决方案,因为我使用的是 process.json 文件。

My Dockerfile :我的 Dockerfile :

FROM node:12.14.1-alpine

 # app name
ENV APP_NAME=mock-api
ENV WORK_DIR /deploy/${APP_NAME}

 # Create app directory
RUN mkdir -p ${WORK_DIR} && \
    chown node:node ${WORK_DIR}

RUN apk add --update gnupg

WORKDIR ${WORK_DIR}

COPY ["yarn.lock", "package.json", "./"]
RUN yarn global add pm2 && yarn install --prod --frozen-lockfile && yarn cache clean

COPY --chown=node:node . .

EXPOSE 3000

USER node

CMD ["pm2-runtime", "--no-daemon", "--raw", "process.json"]

Process.json :进程.json :

{
  "apps": [
    {
      "name": "mock-api",
      "script": "./app.js"
    }
  ]
}

package.json:包.json:

{
  "name": "mock-api",
  "version": "1.0.0",
  "description": "Mock API for the testing environment",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "arorasannidhya@gmail.com",
  "license": "ISC",
  "dependencies": {
    "koa": "2.12.0",
    "koa-joi-router": "^6.0.2",
    "koa-logger": "3.2.1",
    "koa-router": "9.0.1",
    "openpgp": "4.10.4",
    "pm2": "^4.2.3",
    "uuid": "^7.0.2"
  },
  "devDependencies": {
    "nodemon": "^2.0.4"
  }
}

Nodemon is the utility to run the node application (it watches file in the directory and when changed runs index.js or app.js (whatever is your root file)) Nodemon 是运行节点应用程序的实用程序(它监视目录中的文件,并在更改时运行 index.js 或 app.js(无论您的根文件是什么))

It cannot be used to build a docker image, you will need to do something like this https://vsupalov.com/rebuilding-docker-image-development/#:~:text=In%20Conclusion,see%20the%20results%20right%20away !它不能用于构建 docker 镜像,你需要做这样的事情https://vsupalov.com/rebuilding-docker-image-development/#:~:text=In%20Conclusion,see%20the%20results% 20 右%20 远

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在网站上使用Node.JS模块? - How do I use Node.JS modules on my site? 如何使用Forever和Nodemon(Windows)自动重启Node.js应用程序 - How can I automatically restart a Node.js application using Forever and Nodemon (Windows) 如何从我的应用程序创建Docker映像? 使用MongoDB的是node.js应用程序 - How to create Docker-image from my app? It's node.js application that use MongoDB 如何使用 Docker 映像将 Node.js HTTP/2 应用程序部署到 Google Compute Engine 上? - How do I deploy a Node.js HTTP/2 application onto Google Compute Engine using a Docker image? (Windows) 如何修复 nodemon | Node.js - (Windows) How to fix nodemon | Node.js 我可以在Windows Phone 8应用程序中使用Node.js吗? - Can I use Node.js into my windows phone 8 application? 如何在 Next.JS web 应用程序中使用 DocuSign Node.js SDK? - How do I use the DocuSign Node.js SDK in a Next.JS web application? 如何在我的骨干网应用程序中使用node.js和套接字 - How to use node.js and sockets within my backbone application 如何将发布数据发送到服务器端node.js应用程序? - How do I send post data to my server side node.js application? 如何编写可在Node.JS应用程序中全局使用的扩展方法? - How do I write extension methods that can be used globally in my Node.JS application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM