在 Docker 容器内启动 Sails.js 会导致 Grunt 错误
Starting Sails.js inside a Docker container causes a Grunt error
我正在创建一个 Sails.js + MongoDB 应用程序并使用 Docker 在本地 运行 它们。这是我的 Docker 设置的样子:
Docker文件
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
docker-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
如果我理解正确,应该安装 G运行t 和来自 package.json 的软件包,因为映像构建得很好。这可能是上面错误中所说的权限问题吗?如果是,我如何 CHOWN 我的容器内的文件夹?谢谢。
sails g运行t 任务正在尝试在您设置 read_only: true
的 /usr/src/app
卷上创建一个 .tmp
目录,删除只读和它会工作。
显然,该卷将不再是只读的。在正常的 sails 启动期间,应用程序用户将需要写入 .tmp
目录,但不需要写入卷的其余部分。您可以 运行 作为用户使用该应用程序,但没有对容器映像中 /usr/src/app
的写入权限,但可以访问 /usr/src/app/.tmp
我正在创建一个 Sails.js + MongoDB 应用程序并使用 Docker 在本地 运行 它们。这是我的 Docker 设置的样子:
Docker文件
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
docker-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
如果我理解正确,应该安装 G运行t 和来自 package.json 的软件包,因为映像构建得很好。这可能是上面错误中所说的权限问题吗?如果是,我如何 CHOWN 我的容器内的文件夹?谢谢。
sails g运行t 任务正在尝试在您设置 read_only: true
的 /usr/src/app
卷上创建一个 .tmp
目录,删除只读和它会工作。
显然,该卷将不再是只读的。在正常的 sails 启动期间,应用程序用户将需要写入 .tmp
目录,但不需要写入卷的其余部分。您可以 运行 作为用户使用该应用程序,但没有对容器映像中 /usr/src/app
的写入权限,但可以访问 /usr/src/app/.tmp