Dockerizing Vue.js App With NodeJS Backend
Learn How to Dockerize and make it a deployable image
Docker is an enterprise-ready container platform that enables organizations to seamlessly build, share, and run any application, anywhere. Almost every company is containerizing its applications for faster production workloads so that they can deploy anytime and sometimes several times a day. There are so many ways we can build a Vue.js App. 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.
- Introduction
- Example Project
- Dockerizing the App
- Running The App on Docker
- Summary
- Conclusion
Introduction
Nowadays, it’s very common to dockerize and deploy the Docker image in the production with the help of container orchestration engines such as Docker Swarn or Kubernetes. We are going to Dockerize the app and create an image and run it on Docker on our local machine. We could also push that Image into Docker hub and pull it whenever and wherever we need it.
Here is the complete guide on how to develop a Vue.js app with nodejs as a backend server. If you are not familiar with the process or you want to know before studying this guide, I would recommend you going through it.
How To Develop and Build Vue.js App With NodeJS
Prerequisite
As a prerequisite, you have to install Docker for Desktop (whatever your OS is). Please follow this link to install Docker on your laptop. Once installed you can check the Docker info or version with the following commands.
docker info
docker --versionExample Project
This is a simple project which demonstrates developing and running Vue application with NodeJS. We have a simple app in which we can add users, count, and display them at the side, and retrieve them whenever you want.

Here is a Github Link for this example project that you can on your local machine.
// clone the project
git clone https://github.com/bbachi/vuejs-nodejs-example.git// strat the api
cd api
npm install
npm run dev// start the vue app
cd my-app
npm install
npm run serveIf you want to create a Docker image and run it on the local Docker, here are the steps.
// create an image
docker build -t vue-node-image .// running on Image
docker run -it -p 3080:3080 --name vue-node-ui vue-node-imageDockerizing the App
We use the multi-stage builds for efficient docker images. Building efficient Docker images are very important for faster downloads and lesser surface attacks. In this multi-stage build, building a Vue project and put those static assets in the dist folder is the first step. The second step involves taking those static build files and serve those with node server.
Let’s build an image with the Dockerfile. Here are the things we need for building an image.
Stage 1
- Start from the base image
node:10 - There are two package.json files: one is for nodejs server and another is for VueUI. We need to copy these into the Docker file system and install all the dependencies.
- We need this step first to build images faster in case there is a change in the source later. We don’t want to repeat installing dependencies every time we change any source files.
- Copy all the source files.
- Vue uses CLI Service to build the app. So, install CLI and install all the dependencies.
- Run
npm run buildto build the Vue App and all the assets will be created underdista folder within a my-app folder.
Stage 2
- Start from the base image
node:10 - Take the build from stage 1 and copy all the files into ./my-app/dist folder.
- Copy the nodejs package.json
- Install all the dependencies
- Finally, copy the server.js
- Have this command
node server.jswith the CMD. This automatically runs when we run the image.



