Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building Docker for vuejs app

Tags:

docker

vue.js

I have a problem when building docker for vuejs app

I have a vuejs app and now I want to build a docker image for it

This is my Dockerfile

 FROM node:7.7.2-alpine
 WORKDIR /usr/app
 COPY package.json .
 RUN npm install --quiet
 COPY . .
 EXPOSE 8080

And This is my docker-compose.yml file

version: '2'

services:
   web:
      build: .
      command: npm run dev
      volumes:
         - .:/usr/app
         - /usr/app/node_modules
      ports:
         - "8080:8080"

When I run command docker-compose up. I get this result: this result

But when I access the url http://localhost:8080 on my host. I get this: the screen

I don't know exactly what happened. Please help me to fix this problem.

Thank you so much.

These are my source code folders: source code folders

like image 978
Ken Avatar asked Mar 03 '18 10:03

Ken


People also ask

How to build a docker Vue JS image?

Build a Docker Vue JS Image using Dockerfile Start the Container from the Image we have created Validate the web application Running inside Container Securing Vue JS Application using NGINX (Optional) Create a Dockerfile Build a Docker Vue JS Image using Dockerfile

How to dockerize the Vue JS app with NodeJS backend?

One way is to dockerize the Vue.js app with nodejs backend and create a docker image so that we can deploy that image any time or sometimes several times a day. In this post, we look at the example project and see the step by step guide on how we can dockerizing the Vue.js app with nodejs as a server.

Why is Docker shutting down when I run a Vue app?

Secondly you are using CMD ["node"] which does not start your vue application, so there is no job running and docker is shutting down. For vue applicaton you normally want to build the app with static assets and then run a simple http server to serve the static content.

How do I start developing with Vue-Docker?

- Check out the first part of the Vue-Docker series. - Or if you're TL: DR - take me to the code. Now that we have Docker installed and scaffolded our project, we can start developing. Let's begin by adding the following to the Dev.Dockerfile:


1 Answers

By default npm run dev binds to localhost only.

Add --host 0.0.0.0 to your webpack-dev-server line in package.json:

From something like:

  "scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",

To something like (add --host 0.0.0.0):

    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --host 0.0.0.0",
like image 174
acdcjunior Avatar answered Oct 24 '22 05:10

acdcjunior