DevOps Config Files Guide
Dockerfiles
A Dockerfile is a text file with instructions for building a Docker container image. Each instruction creates a layer in the image.
FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . EXPOSE 3000 CMD ["node", "dist/index.js"]
- FROM: Base image to build on
- COPY: Copy files from host to container
- RUN: Execute commands during build
- CMD: Default command when container starts
- Multi-stage builds: Use separate FROM stages for smaller production images
Nginx Configuration
Nginx configs define server blocks that handle HTTP requests, routing, SSL, proxying, caching, and compression.
server {
listen 80;
server_name example.com;
root /var/www/html;
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(js|css|png|jpg)$ {
expires 30d;
}
}.gitignore Files
A .gitignore file tells Git which files and directories to exclude from version control. Patterns use glob syntax.
# Dependencies node_modules/ # Build output dist/ build/ # Environment files .env .env.local # OS files .DS_Store Thumbs.db
- Lines starting with # are comments
- Trailing / matches directories only
- * matches any characters except /
- ** matches any path (including nested directories)
- Prefix with ! to negate (un-ignore) a pattern
Best Practices
- Always use .dockerignore to exclude node_modules and other large directories from Docker builds
- Use alpine-based images when possible for smaller container sizes
- Never commit .env files, add them to .gitignore
- Use Let's Encrypt for free SSL certificates in nginx
- Enable gzip compression for text-based responses