JackH
JackH

Reputation: 4735

Starting Sails.js inside a Docker container causes a Grunt error

I'm creating a Sails.js + MongoDB application and using Docker to run them locally. This is what my Docker setup looks like:

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 [email protected] 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

My image builds just fine however, when I run docker-compose up, I see the following error:

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

If I understand correctly, Grunt and my packages from package.json should be installed because the image builds just fine. Could this be an issue with permissions as it says in the error above? If yes, how do I CHOWN the folder inside my container? Thanks.

Upvotes: 1

Views: 668

Answers (1)

Matt
Matt

Reputation: 74680

The sails grunt task is trying to create a .tmp directory on the /usr/src/app volume you have set read_only: true on, remove the read only and it will work.

Obviously that volume won't be read only any more. The app user will need to write to the .tmp directory during the normal sails startup but not to the rest of the volume. You could run the app as a user without write privileges to /usr/src/app in the container image but with access to /usr/src/app/.tmp

Upvotes: 1

Related Questions