Document how to dockerize a Vue app
See original GitHub issueDescription
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:
- is this the best approach (or even a correct one)?
- 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)- 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:
- Created 6 years ago
- Reactions:10
- Comments:17 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@williamhallatt @sdras disregard to above solution… as there is a much better way. Docker mulit-stage builds. Please see new Dockerfile below;
No need for custom nginx conf files and reduces my Docker image from 276MB to 110MB 😃
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:
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.