content/guides/vuejs/develop.md
Complete Containerize Vue.js application.
In this section, you'll set up both production and development environments for your Vue.js application using Docker Compose. This approach streamlines your workflow—delivering a lightweight, static site via Nginx in production, and providing a fast, live-reloading dev server with Compose Watch for efficient local development.
You’ll learn how to:
Leverage Compose Watch to enable real-time file synchronization between your local machine and the containerized Vue.js development environment. This powerful feature eliminates the need to manually rebuild or restart containers, providing a fast, seamless, and efficient development workflow.
With Compose Watch, your code updates are instantly reflected inside the container—perfect for rapid testing, debugging, and live previewing changes.
Create a file named Dockerfile.dev in your project root with the following content:
# =========================================
# Stage 1: Develop the Vue.js Application
# =========================================
ARG NODE_VERSION=24.12.0-alpine
# Use a lightweight Node.js image for development
FROM node:${NODE_VERSION} AS dev
# Set environment variable to indicate development mode
ENV NODE_ENV=development
# Set the working directory inside the container
WORKDIR /app
# Copy package-related files first to leverage Docker's caching mechanism
COPY package.json package-lock.json* ./
# Install project dependencies
RUN --mount=type=cache,target=/root/.npm npm install
# Copy the rest of the application source code into the container
COPY . .
# Change ownership of the application directory to the node user
RUN chown -R node:node /app
# Switch to the node user
USER node
# Expose the port used by the Vite development server
EXPOSE 5173
# Use a default command, can be overridden in Docker compose.yml file
CMD [ "npm", "run", "dev", "--", "--host" ]
This file sets up a lightweight development environment for your Vue.js application using the dev server.
compose.yaml fileOpen your compose.yaml file and define two services: one for production (vuejs-prod) and one for development (vuejs-dev).
Here’s an example configuration for an Vue.js application:
services:
vuejs-prod:
build:
context: .
dockerfile: Dockerfile
image: docker-vuejs-sample
ports:
- "8080:8080"
vuejs-dev:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "5173:5173"
develop:
watch:
- path: ./src
target: /app/src
action: sync
- path: ./package.json
target: /app/package.json
action: restart
- path: ./vite.config.js
target: /app/vite.config.js
action: restart
vuejs-prod service builds and serves your static production app using Nginx.vuejs-dev service runs your Vue.js development server with live reload and hot module replacement.watch triggers file sync with Compose Watch.[!NOTE] For more details, see the official guide: Use Compose Watch.
After completing the previous steps, your project directory should now contain the following files:
├── docker-vuejs-sample/
│ ├── Dockerfile
│ ├── Dockerfile.dev
│ ├── .dockerignore
│ ├── compose.yaml
│ ├── nginx.conf
│ └── README.Docker.md
Run the following command from the project root to start the container in watch mode
$ docker compose watch vuejs-dev
To confirm that Compose Watch is functioning correctly:
Open the src/App.vue file in your text editor.
Locate the following line:
<HelloWorld msg="You did it!" />
Change it to:
<HelloWorld msg="Hello from Docker Compose Watch" />
Save the file.
Open your browser at http://localhost:5173.
You should see the updated text appear instantly, without needing to rebuild the container manually. This confirms that file watching and automatic synchronization are working as expected.
In this section, you set up a complete development and production workflow for your Vue.js application using Docker and Docker Compose.
Here’s what you accomplished:
Dockerfile.dev to streamline local development with hot reloadingvuejs-dev and vuejs-prod services in your compose.yaml fileWith this setup, you're now equipped to build, run, and iterate on your Vue.js app entirely within containers—efficiently and consistently across environments.
Deepen your knowledge and improve your containerized development workflow with these guides:
compose.yaml.In the next section, you'll learn how to run unit tests for your Vue.js application inside Docker containers. This ensures consistent testing across all environments and removes dependencies on local machine setup.