When you deploy an application without a Dockerfile, Containarium automatically detects your programming language and generates an appropriate Dockerfile. This document describes the detection rules and generated Dockerfiles for each supported language.
Languages are detected in this order (first match wins):
- Node.js -
package.json - Python -
requirements.txt,Pipfile, orpyproject.toml - Go -
go.mod - Rust -
Cargo.toml - Ruby -
Gemfile - PHP -
composer.json - Static -
index.html
If multiple marker files exist, the first matching language in this list is used.
Detection: package.json in project root
Auto-detected Settings:
- Node version: From
engines.nodein package.json, or defaults to20 - Start command: Based on presence of
server.js,index.js,app.js,main.js, or defaults tonpm start - Next.js detection: Automatically detected via
next.config.*files
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/', (r) => process.exit(r.statusCode === 200 ? 0 : 1))" || exit 1
CMD ["npm", "start"]For Next.js projects, a multi-stage build is generated:
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
EXPOSE 3000
CMD ["node", "server.js"]Requirements:
- Set
output: 'standalone'innext.config.jsfor standalone builds
Detection: requirements.txt, Pipfile, or pyproject.toml
Auto-detected Settings:
- Python version: Defaults to
3.12 - Framework detection: Flask, Django, FastAPI
FROM python:3.12-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends gcc && rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
ENV FLASK_APP=app.py
ENV FLASK_ENV=production
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "4", "app:app"]Detected by presence of manage.py:
FROM python:3.12-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends gcc libpq-dev && rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
RUN python manage.py collectstatic --noinput || true
EXPOSE 8000
ENV DJANGO_SETTINGS_MODULE=config.settings
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "4", "config.wsgi:application"]FROM python:3.12-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends gcc && rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]Note: Install gunicorn or uvicorn in your requirements.txt for production deployments.
Detection: go.mod in project root
Auto-detected Settings:
- Go version: From
go.mod, or defaults to1.22 - Main package: Detected from
main.golocation (./,./cmd/server,./cmd/app)
FROM golang:1.22-alpine AS builder
WORKDIR /app
RUN apk add --no-cache git ca-certificates tzdata
COPY go.mod go.sum* ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags='-w -s -extldflags "-static"' \
-o /app/server .
FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /app/server /server
EXPOSE 8080
ENTRYPOINT ["/server"]Features:
- Multi-stage build for minimal image size
- Static binary (no CGO)
- Includes CA certificates for HTTPS
- Timezone data included
Detection: Cargo.toml in project root
FROM rust:1.75 AS builder
WORKDIR /app
RUN USER=root cargo new --bin app
WORKDIR /app/app
COPY Cargo.toml Cargo.lock* ./
RUN cargo build --release
RUN rm src/*.rs
COPY src ./src
RUN rm ./target/release/deps/app*
RUN cargo build --release
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=builder /app/app/target/release/app ./app
EXPOSE 8080
CMD ["./app"]Features:
- Dependency caching for faster builds
- Multi-stage build
- Minimal runtime image
Detection: Gemfile in project root
Detected by presence of config.ru and Rakefile:
FROM ruby:3.3-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends build-essential libpq-dev nodejs npm && rm -rf /var/lib/apt/lists/*
COPY Gemfile Gemfile.lock* ./
RUN bundle install --without development test
COPY . .
RUN RAILS_ENV=production bundle exec rake assets:precompile || true
EXPOSE 3000
ENV RAILS_ENV=production
ENV RAILS_LOG_TO_STDOUT=true
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]FROM ruby:3.3-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends build-essential libpq-dev && rm -rf /var/lib/apt/lists/*
COPY Gemfile Gemfile.lock* ./
RUN bundle install --without development test
COPY . .
EXPOSE 3000
CMD ["ruby", "app.rb"]Detection: composer.json in project root
Detected by presence of artisan:
FROM php:8.3-fpm
WORKDIR /var/www/html
RUN apt-get update && apt-get install -y --no-install-recommends libpng-dev libonig-dev libxml2-dev zip unzip nginx supervisor && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY composer.json composer.lock ./
RUN composer install --no-dev --optimize-autoloader
COPY . .
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
RUN php artisan key:generate --force || true
RUN php artisan config:cache || true
EXPOSE 80
CMD service php8.3-fpm start && nginx -g "daemon off;"FROM php:8.3-apache
WORKDIR /var/www/html
RUN apt-get update && apt-get install -y --no-install-recommends libpng-dev libonig-dev libxml2-dev zip unzip && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY composer.json composer.lock* ./
RUN composer install --no-dev --optimize-autoloader
COPY . .
RUN chown -R www-data:www-data /var/www/html
RUN a2enmod rewrite
EXPOSE 80
CMD ["apache2-foreground"]Detection: index.html in project root or common build directories (dist/, public/, build/, out/)
FROM nginx:alpine
COPY . /usr/share/nginx/html
RUN echo 'server { \
listen 80; \
server_name localhost; \
root /usr/share/nginx/html; \
index index.html; \
location / { \
try_files $uri $uri/ /index.html; \
} \
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { \
expires 1y; \
add_header Cache-Control "public, immutable"; \
} \
gzip on; \
gzip_types text/plain text/css application/json application/javascript text/xml application/xml; \
}' > /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]Features:
- SPA routing support (fallback to index.html)
- Asset caching headers
- Gzip compression
Auto-detected document root:
dist/- Common for Vite, Webpackpublic/- Common for Create React Appbuild/- Common for various frameworksout/- Common for Next.js static export.- If index.html is in root
Specify language versions during deployment:
containarium app deploy myapp --source . \
--buildpack-node-version 18 \
--server <host:port> --user <username>For full control, create a Dockerfile in your project root. Containarium will use it instead of auto-generating one.
- Lock your dependencies: Use lock files (package-lock.json, Pipfile.lock, go.sum, etc.)
- Use .dockerignore: Exclude unnecessary files from the build context
- Set explicit ports: Ensure your app listens on the expected port
- Handle environment variables: Read config from environment variables
- Implement health checks: Add a
/healthendpoint for monitoring