Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue.js app on a docker container with hot reload

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?

like image 710
dev1234 Avatar asked Nov 11 '18 06:11

dev1234


People also ask

Does Vue support hot reloading?

Vuex supports hot-reloading mutations, modules, actions and getters during development, using webpack's Hot Module Replacement API. You can also use it in Browserify with the browserify-hmr plugin. Checkout the counter-hot example to play with hot-reload.

How do I enable hot reload in Vue?

When scaffolding the project with vue-cli , Hot Reload is enabled out-of-the-box. When manually setting up your project, hot-reload is enabled automatically when you serve your project with webpack-dev-server --hot . Advanced users may want to check out vue-hot-reload-api , which is used internally by vue-loader .


1 Answers

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
like image 129
Brian Lee Avatar answered Oct 01 '22 13:10

Brian Lee