Skip to content

Instantly share code, notes, and snippets.

@adityawasudeo
Created July 9, 2025 18:50
Show Gist options
  • Save adityawasudeo/3ba442a36ef90202312e04cbc1943da2 to your computer and use it in GitHub Desktop.
Save adityawasudeo/3ba442a36ef90202312e04cbc1943da2 to your computer and use it in GitHub Desktop.
Running Vite + TS React in a dev container
services:
init:
profiles: ["init"]
build:
context: app
target: init
volumes:
- ./app:/app
- /app/node_modules
command: >
sh -c "
if [ ! -f vite.config.ts ]; then
echo 'Creating new Vite React+TypeScript project...'
npm create vite@latest . -- --template react-ts
else
echo 'Project already exists. Skipping creation.'
fi
"
dev:
profiles: ["dev"]
env_file:
- .env.dev
ports:
- "5173:5173"
build:
context: app
target: dev
volumes:
- ./app:/app
- /app/node_modules
stdin_open: true
tty: true
FROM node:20-alpine AS init
RUN mkdir /app
WORKDIR /app
COPY package.json ./
COPY . .
FROM node:20-alpine AS dev
RUN mkdir /app
WORKDIR /app
COPY package.json ./
RUN npm install
RUN npm ci
CMD ["npm", "run", "dev"]
1. Create a directory called /app
2. Build the environment:
`docker compose run --rm init`
3. Run the container:
`docker compose up dev`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment