LiveKit Dockerfile Backend Tutorial
Build Your LiveKit Dockerfile
Create a production-ready Dockerfile for your LiveKit application with our interactive guide. Learn best practices and optimize your container for security and performance.
Interactive Tutorial
Step-by-step guide to create the perfect Dockerfile for your LiveKit application.
Comprehensive Documentation
Detailed explanations of each Dockerfile component with best practices.
FAQ Section
Answers to common questions and troubleshooting tips for Docker deployments.
Final Dockerfile Preview
# syntax=docker/dockerfile:1
FROM --platform=linux/amd64 node:20-slim
# Create a non-privileged user
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/home/appuser" \
--shell "/sbin/nologin" \
--uid "${UID}" \
appuser
WORKDIR /app
# Set environment variables
ENV LIVEKIT_URL=wss://inserlivekitcredentialshere.livekit.cloud
ENV LIVEKIT_API_KEY=APIenteryourlivekitapihere
ENV LIVEKIT_API_SECRET=enteryourlivekitapisecrethere
ENV OPENAI_API_KEY=sk-enteryouropenaicredentialshere
# Install dependencies and build tools
RUN apt-get update && apt-get install -y ca-certificates openssl wget python3 make g++ && \
update-ca-certificates && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Copy only necessary files (package.json, package-lock.json)
COPY package*.json ./
COPY tsconfig.json ./
# Install all dependencies including dev dependencies
RUN npm install --legacy-peer-deps
# Copy the rest of the application
COPY . .
# Build TypeScript code
RUN npm run build
# Clean up by removing devDependencies while keeping the legacy-peer-deps flag
RUN npm prune --omit=dev --legacy-peer-deps
COPY .env .env
COPY .env.local .env.local
# Switch to non-root user
USER appuser
# Expose the port your app runs on (If needed for web server)
EXPOSE 3000
# Start in production mode
CMD ["node", "dist/agent.js", "start"]