Docker helps package your Vue app with everything it needs to run. This makes it easy to share and deploy your app anywhere.
Docker deployment for Vue apps
FROM node:18-alpine AS build WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build FROM nginx:stable-alpine COPY --from=build /app/dist /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
This Dockerfile uses two stages: one to build the Vue app, one to serve it with Nginx.
Use npm run build to create optimized files in the dist folder.
FROM node:18-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run buildFROM nginx:stable-alpine COPY --from=build /app/dist /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
This Dockerfile builds your Vue app and serves it with Nginx. First, it installs dependencies and builds the app. Then it copies the build output to Nginx's web folder and runs Nginx to serve your app on port 80.
# Dockerfile FROM node:18-alpine AS build WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build FROM nginx:stable-alpine COPY --from=build /app/dist /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
Make sure your Vue app's package.json and source files are in the same folder as the Dockerfile.
Use docker build -t my-vue-app . to build the image.
Run with docker run -p 80:80 my-vue-app to access the app in your browser.
Docker packages your Vue app and its environment for easy deployment.
Use a multi-stage Dockerfile: build with Node, serve with Nginx.
Run the container and open your browser to see your Vue app live.