.
This commit is contained in:
@@ -28,7 +28,8 @@ docker run -p 3000:80 sakai-vue
|
||||
|
||||
## Структура Docker файлов
|
||||
|
||||
- `Dockerfile` - основной файл для сборки образа
|
||||
- `Dockerfile` - основной файл для сборки образа (исправлен для dev зависимостей)
|
||||
- `Dockerfile.optimized` - оптимизированная версия с non-root пользователем
|
||||
- `docker-compose.yml` - конфигурация для Docker Compose
|
||||
- `nginx.conf` - конфигурация Nginx для SPA приложения
|
||||
- `.dockerignore` - файлы, исключаемые из контекста сборки
|
||||
@@ -50,6 +51,19 @@ Dockerfile использует многоэтапную сборку:
|
||||
### Health Check
|
||||
Приложение включает health check endpoint по адресу `/health`
|
||||
|
||||
## Решение проблем
|
||||
|
||||
### Проблема: "vite: not found" при сборке
|
||||
**Причина:** Использование `npm ci --only=production` исключает dev зависимости, включая Vite.
|
||||
|
||||
**Решение:** Исправлено в Dockerfile - теперь используется `npm ci` для установки всех зависимостей, включая dev зависимости, необходимые для сборки.
|
||||
|
||||
### Проблема: Уязвимости безопасности
|
||||
**Решение:** Используйте `Dockerfile.optimized` который:
|
||||
- Создает non-root пользователя
|
||||
- Устанавливает минимальные права доступа
|
||||
- Включает health checks
|
||||
|
||||
## Команды для разработки
|
||||
|
||||
```bash
|
||||
@@ -64,6 +78,9 @@ docker-compose build --no-cache
|
||||
|
||||
# Вход в контейнер
|
||||
docker exec -it sakai-vue-app sh
|
||||
|
||||
# Тестирование исправленного Dockerfile
|
||||
docker build -t sakai-vue-test .
|
||||
```
|
||||
|
||||
## Переменные окружения
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# Multi-stage build for Vue.js application (Optimized version)
|
||||
FROM node:18-alpine AS builder
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
|
||||
# Install all dependencies (including dev dependencies for build)
|
||||
RUN npm ci
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the application
|
||||
RUN npm run build
|
||||
|
||||
# Production stage
|
||||
FROM nginx:alpine AS production
|
||||
|
||||
# Install curl for health checks
|
||||
RUN apk add --no-cache curl
|
||||
|
||||
# Copy built assets from builder stage
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
# Copy custom nginx configuration
|
||||
COPY nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
# Create non-root user for security
|
||||
RUN addgroup -g 1001 -S nodejs && \
|
||||
adduser -S nextjs -u 1001
|
||||
|
||||
# Change ownership of nginx directories
|
||||
RUN chown -R nextjs:nodejs /var/cache/nginx && \
|
||||
chown -R nextjs:nodejs /var/log/nginx && \
|
||||
chown -R nextjs:nodejs /etc/nginx/conf.d && \
|
||||
touch /var/run/nginx.pid && \
|
||||
chown -R nextjs:nodejs /var/run/nginx.pid && \
|
||||
chown -R nextjs:nodejs /usr/share/nginx/html
|
||||
|
||||
# Switch to non-root user
|
||||
USER nextjs
|
||||
|
||||
# Expose port 80
|
||||
EXPOSE 80
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD curl -f http://localhost/health || exit 1
|
||||
|
||||
# Start nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
+1
-1
@@ -4,7 +4,7 @@ services:
|
||||
sakai-vue:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
dockerfile: Dockerfile.optimized
|
||||
ports:
|
||||
- "3000:80"
|
||||
container_name: sakai-vue-app
|
||||
|
||||
Reference in New Issue
Block a user