question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document how to dockerize a Vue app

See original GitHub issue

Description

It would be nice to add a small section (maybe in the Production Deployment page) which shows how to create a production-like docker image of a Vue app built out of an official template (e.g. webpack).

This comes out of my question in the #need-help channel:

I’m trying to create a production-like docker image capable of serving my Vue.js app (built starting from the official Vue.js webpack template).

I came up with something like this:

FROM node:9.3.0-alpine

# install static server
RUN npm install -g serve

# create a 'tmp' folder for the build and make it the current working directory
WORKDIR /app/tmp

# copy only the package.json to take advantage of cached Docker layers
COPY package.json .

# install project dependencies
RUN npm install

# copy project files and folders to the working directory
COPY . .

# build for production with minification
RUN npm run build

# make the 'app' folder the current working directory
WORKDIR /app

# clean up (i.e. extract 'dist' folder and remove everything else)
RUN mv tmp/dist dist && rm -fr tmp

EXPOSE 5000
CMD [ "serve", "--single", "--port", "5000", "dist" ]

Considering I’m a Vue.js newbie:

  1. is this the best approach (or even a correct one)?
  2. all examples I’ve found googling around just copy the whole project folder inside the docker container and use the npm run dev command to serve the app with webpack. Is this a preferable approach? (although I guess in this case the non-minified app will be served)
  3. is there an official documentation that clearly describe the best way to dockerize a Vue.js app? (apologies if there is and I missed it)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

7reactions
fredderf204commented, May 16, 2018

@williamhallatt @sdras disregard to above solution… as there is a much better way. Docker mulit-stage builds. Please see new Dockerfile below;

FROM node:8.9-alpine as builder
WORKDIR /app
COPY package.json .
RUN yarn install
COPY . .
RUN npm run build

FROM nginx
COPY --from=builder /app/dist /usr/share/nginx/html

No need for custom nginx conf files and reduces my Docker image from 276MB to 110MB 😃

6reactions
sdrascommented, Dec 31, 2017

I think this a great idea. I have a dockerfile that I’ve been using for Vue applications as well, I could see it in the cookbook and linked to from deployment, as Dockerfiles can be set up many ways, and there is not one true way. Here is my nginx version:

FROM node:alpine

EXPOSE 80

RUN apk add --no-cache nginx

WORKDIR /app

COPY package.json .
RUN yarn install

COPY misc/nginx.conf /etc/nginx/nginx.conf

COPY . .

RUN yarn run generate

CMD ["nginx"]

The only thing I’d say is that the cleanup step adds an unnecessary layer to the image, but that might be something worth documenting and talking through in the cookbook example.

Unless you are interested in writing it, I can make the cookbook example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dockerize Vue.js App
Dockerize Vue.js App. Simple Example. So you built your first Vue.js app using the amazing Vue.js webpack template and now you really want...
Read more >
Docker VueJS Example | DevOps Junction
Step 1: Creating a Dockerfile · Step 2: Build a Docker Vue JS image using Dockerfile · Step 3: Start the container from...
Read more >
Dockerizing a Vue App - Michael Herman
This tutorial looks at how to Dockerize a Vue app, built with the Vue CLI, using Docker along with Docker Compose and Docker...
Read more >
A step-by-step guide to develop and deploy Vue apps with ...
This series of articles will equip you with the knowledge to create, develop and deploy a Vue project with Docker. With some tweaks,...
Read more >
Vue with Docker; initialize, develop and build | by Joost Döbken
Let's initialize a Vue project from a docker container; build the Vue project with a multi-stage Dockerfile; and finish with how to develop...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found