我正在创建一个Sails.js + MongoDB应用程序并使用Docker在本地运行它们。这就是我的Docker设置:
Dockerfile
FROM node:8.9.3-alpine
LABEL Name=web-service Version=1.0.0
# Container configuration
ENV NODE_ENV development
WORKDIR /usr/src/app
COPY ["package.json", "npm-shrinkwrap.json*", "./"]
RUN npm install -g sails@0.12.4 grunt nodemon && npm install && mv node_modules ../
VOLUME /usr/src/app
EXPOSE 1337
CMD nodemon
搬运工-compose.yml
version: '3.4'
services:
web-service:
image: web-service:latest
build: .
environment:
NODE_ENV: development
ports:
- 1338:1337 # HOST_PORT is 1338 to avoid conflicts with other Sails.js apps running on host
volumes:
- type: volume
source: .
target: /usr/src/app
read_only: true
mongoDb:
image: mongo:3.6
ports:
- 27018:27017 # HOST_PORT is 27018 to avoid conflicts with other MongoDB databases running on host
volumes:
- ./volumes/mongodb:/data/db
我的图片构建得很好但是,当我运行docker-compose up
时,我看到以下错误:
web-service_1 | [nodemon] starting `node app.js`
web-service_1 | info:
web-service_1 | info: .-..-.
web-service_1 | info:
web-service_1 | info: Sails <| .-..-.
web-service_1 | info: v0.12.4 |\
web-service_1 | info: /|.\
web-service_1 | info: / || \
web-service_1 | info: ,' |' \
web-service_1 | info: .-'.-==|/_--'
web-service_1 | info: `--'-------'
web-service_1 | info: __---___--___---___--___---___--___
web-service_1 | info: ____---___--___---___--___---___--___-__
web-service_1 | info:
web-service_1 | info: Server lifted in `/usr/src/app`
web-service_1 | info: To see your app, visit http://localhost:1337
web-service_1 | info: To shut down Sails, press <CTRL> + C at any time.
web-service_1 |
web-service_1 | debug: -------------------------------------------------------
web-service_1 |
web-service_1 | debug: :: Wed Jan 10 2018 18:37:23 GMT+0000 (UTC)
web-service_1 | debug: Environment : development
web-service_1 | debug: Port : 1337
web-service_1 | debug: -------------------------------------------------------
web-service_1 |
web-service_1 |
web-service_1 | error:
web-service_1 | ------------------------------------------------------------------------
web-service_1 | Fatal error: Unable to create directory "/usr/src/app/.tmp" (Error code: EROFS).
web-service_1 | Running "less:dev" (less) task
web-service_1 | ------------------------------------------------------------------------
web-service_1 | error: Looks like a Grunt error occurred--
web-service_1 | error: Please fix it, then **restart Sails** to continue running tasks (e.g. watching for changes in assets)
web-service_1 | error: Or if you're stuck, check out the troubleshooting tips below.
web-service_1 | error: Troubleshooting tips:
web-service_1 | error:
web-service_1 | error: *-> Are "grunt" and related grunt task modules installed locally? Run `npm install` if you're not sure.
web-service_1 | error:
web-service_1 | error: *-> You might have a malformed LESS, SASS, CoffeeScript file, etc.
web-service_1 | error:
web-service_1 | error: *-> Or maybe you don't have permissions to access the `.tmp` directory?
web-service_1 | error: e.g., `/usr/src/app/.tmp` ?
web-service_1 | error:
web-service_1 | error: If you think this might be the case, try running:
web-service_1 | error: sudo chown -R YOUR_COMPUTER_USER_NAME /usr/src/app/.tmp
如果我理解正确,应该安装Grunt和我在package.json中的包,因为图像构建得很好。这可能是权限问题,如上面的错误所述?如果是,我该如何清除容器内的文件夹?感谢。
答案 0 :(得分:1)
sails grunt任务是尝试在您设置.tmp
的{{1}}卷上创建/usr/src/app
目录,删除只读,它将起作用。
显然,该卷将不再被读取。应用程序用户需要在正常风帆启动期间写入read_only: true
目录,但不能写入卷的其余部分。您可以作为用户运行应用程序而无需对容器图像中的.tmp
具有写入权限,但可以访问/usr/src/app