Vue.js app on a docker container with hot reload

人走茶凉 提交于 2019-12-04 11:27:51

问题


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


来源:https://stackoverflow.com/questions/53246267/vue-js-app-on-a-docker-container-with-hot-reload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!