【发布时间】:2022-02-03 02:28:43
【问题描述】:
您好,我正在尝试对我当前正在开发的应用程序进行 dockerize。它使用 nodejs 和 mariadb。我在弄清楚如何使 nodemon 工作时遇到了一些困难。
我尝试使用--legacy-watch 或-L 这是简短的形式,但它并没有改变结果。
NPM 正确安装了所有依赖项,我什至得到了 nodemon 文本,但是当我进行更改时它不会重新启动服务器。
如果有人可以帮忙,我会很高兴
package.json:
{
"name": "nodejs_mariadb_docker_test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node src/index.js",
"dev": "nodemon -L src/index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.2",
"mariadb": "^2.5.5",
"nodemon": "^2.0.15"
}
}
nodejs 的 Dockerfile:
# Specifies the image of your engine
FROM node:16.13.2
# The working directory inside your container
WORKDIR /app
# Get the package.json first to install dependencies
COPY package.json /app
# This will install those dependencies
RUN npm install
# Copy the rest of the app to the working directory
COPY . /app
# Run the container
CMD ["npm", "run", "dev"]
和 docker compose 文件:
version: "3"
services:
node:
build: .
container_name: express-api
ports:
- "80:8000"
depends_on:
- mysql
mysql:
image: mariadb:latest
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: "password"
volumes:
- mysqldata:/var/lib/mysql
- ./mysql-dump:/docker-entrypoint-initdb.d
volumes:
mysqldata: {}
【问题讨论】: