-->

Vue.js app on a docker container with hot reload

2020-05-27 11:54发布

问题:

I have a signifiant delay and high cpu usage when running my vue.js app on docker instance.

This is my docker setup

docker-compose.yml

version: '2'
services:

  app:
    build:
      context: ./
      dockerfile: docker/app.docker
    working_dir: /usr/src/app
    volumes:
    - ~/.composer-docker/cache:/root/.composer/cache:delegated
    - ./:/usr/src/app
    stdin_open: true
    tty: true
    environment:
    - HOST=0.0.0.0
    - CHOKIDAR_USEPOLLING=true
    ports:
    - 8080:8080

app.docker

# base image
FROM node:8.10.0-alpine

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
COPY package*.json ./

RUN npm install

# Bundle app source
COPY . .

EXPOSE 8080

CMD [ "npm", "run", "serve"]

this setup works fine when i type docker-compose up -d and my app is loading in http://localhost:8080/ but hot reloading happens after 10 seconds , then 15 seconds like wise it keeps increasing and my laptop cpu usage gets 60% and still increasing

i am on a mac book pro with 16 gb ram, and for docker i have enabled 4 cpu's and 6 gb ram.

how can this issue be resolved?

回答1:

Add one of the delegated or cached options to the volume mounting your app directory. I've experienced significant performance increases using cached in particular:

volumes:
  - ~/.composer-docker/cache:/root/.composer/cache:delegated
  - ./:/usr/src/app:cached