Docker Config Reference (Dockerfile)

We put out a large example of dockerfile configurations for you to use!

Docker Config Reference (Dockerfile)
Dockerfile Examples

1. Minimal Alpine Linux Base Image

This Dockerfile creates a lightweight base image using Alpine Linux, suitable for minimalistic applications or as a starting point for custom builds.

FROM alpine:latest

LABEL maintainer="example@domain.com"

RUN apk update && apk upgrade

CMD ["echo", "Hello from Alpine!"]

2. Node.js Web Application

This example builds a Node.js application, installing dependencies and exposing a port for a simple web server.

FROM node:20-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]

3. Python Flask Application

This Dockerfile sets up a Python environment for a Flask web application, managing dependencies via pip.

FROM python:3.12-slim

WORKDIR /app

COPY requirements.txt ./

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 5000

CMD ["python", "app.py"]

4. Nginx Static Web Server

This configures Nginx to serve static HTML content, copying files into the container.

FROM nginx:alpine

COPY ./html /usr/share/nginx/html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

5. MySQL Database Server

This Dockerfile creates a MySQL database image with initialized environment variables for configuration.

FROM mysql:8.0

ENV MYSQL_DATABASE=mydb \
    MYSQL_ROOT_PASSWORD=secret

COPY ./init.sql /docker-entrypoint-initdb.d/

EXPOSE 3306

6. Multi-Stage Go Application Build

This uses multi-stage builds to compile a Go binary and produce a minimal runtime image.

FROM golang:1.21 AS builder

WORKDIR /app

COPY . .

RUN go mod download
RUN go build -o main .

FROM alpine:latest

WORKDIR /root/

COPY --from=builder /app/main .

CMD ["./main"]

7. Java Spring Boot Application

This builds a Spring Boot application, assuming a JAR file is produced via Maven.

FROM openjdk:21-jdk-slim

WORKDIR /app

COPY target/myapp.jar app.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "app.jar"]

8. PHP with Apache Web Server

This sets up a PHP environment with Apache, suitable for dynamic web applications.

FROM php:8.3-apache

COPY ./src /var/www/html

RUN docker-php-ext-install mysqli pdo_mysql

EXPOSE 80

9. Redis Cache Server

This Dockerfile configures a Redis instance with a custom configuration file.

FROM redis:7-alpine

COPY redis.conf /usr/local/etc/redis/redis.conf

CMD ["redis-server", "/usr/local/etc/redis/redis.conf"]

EXPOSE 6379

10. Ubuntu with Custom Tools

This example creates an Ubuntu-based image with additional tools installed, useful for development environments.

FROM ubuntu:24.04

RUN apt-get update && apt-get install -y \
    curl \
    git \
    vim \
    && rm -rf /var/lib/apt/lists/*

CMD ["/bin/bash"]