我在使用Docker容器时遇到问题。到目前为止,我已经通过我的项目生成了所有必需的依赖项。但是调用nodemon
或forever
时遇到问题。基本上,当我更改主机上的某些代码时,这些更改会反映在我的容器中,但是服务器不会重新加载。请帮助我,这是我的容器代码以及更多内容:
Dockerfile :
FROM node:8.10
COPY package.json /usr/src/
WORKDIR /usr/src
RUN npm install
# RUN npm install -g nodemon
RUN npm install -g forever
COPY . /usr/src/
EXPOSE 1337
# CMD ["nodemon", "-w", "api", "-w", "config"]
CMD ["forever", "-w", "start", "app.js"]
docker-compose.yml
version: "3"
services:
app:
build: .
depends_on:
- db
environment:
MYSQL_URL: "mysql://db:3306/app"
ports:
- "3000:1337"
volumes:
- /c/Users/German/Documents/Prueba/DockerSails/:/usr/src/
- /usr/src/node_modules
db:
image: mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
package.json
{
"name": "docker-sails",
"private": true,
"version": "0.0.0",
"description": "a Sails application",
"keywords": [],
"dependencies": {
"sails": "^1.1.0",
"sails-hook-orm": "^2.1.1",
"sails-hook-sockets": "^1.5.5",
"@sailshq/lodash": "^3.10.3"
},
"devDependencies": {
"@sailshq/eslint": "^4.19.3",
"nodemon": "^1.18.9"
},
"scripts": {
"start": "NODE_ENV=production node app.js",
"test": "npm run lint && npm run custom-tests && echo 'Done.'",
"lint": "eslint . --max-warnings=0 --report-unused-disable-directives && echo '✔ Your .js files look good.'",
"custom-tests": "echo \"(No other custom tests yet.)\" && echo",
"dev": "nodemon"
},
"main": "app.js",
"repository": {
"type": "git",
"url": "git://github.com/german/docker-sails.git"
},
"author": "german",
"license": "",
"engines": {
"node": "^8.10"
}
}
重现步骤:我使用docker-compose up --build -d
命令启动容器,并且启动良好,然后转到localhost:3000
的浏览器并查看我的页面。然后,我对代码进行了一些更改,重新加载了浏览器页面,没有任何反应。键入docker-compose exec app /bin/bash
并导航到更改后的文件,我可以看到如何成功更改文件,但是服务器没有重新启动。当我直接在容器上更改某些文件时,服务器可以正常重启