Core Dockerfile Instructions
Base Image Specification
Purpose
Defines the foundation image for the container.
Syntax
FROM <image-name>
FROM <image-name>:<tag>
FROM <image-name>@<digest>
Example using a Python environment with ODBC support:
FROM tadeorubio/pyodbc-msodbcsql17:latest
Key Points
- Must be the first non-comment instruction
- Omittting tag/digest defaults to 'latest' version
Maintainer Information
Purpose
Identifies the image creator
Syntax
LABEL maintainer="Your Name"
Execution Commands
Purpose
Runs commands during image build process
Working Directory
Purpose
Sets the container's default directory
Syntax
WORKDIR /app/project
Port Exposure
Purpose
Declares container network ports
Syntax
EXPOSE 8080
Container Startup Command
Purpose
Defines default execution when container starts
Complete Implementatoin Example
# Base image with Python and SQL connectivity
FROM tadeorubio/pyodbc-msodbcsql17:latest
# Metadata
LABEL maintainer="developer@example.com"
# Environment configuration
ENV PYTHONUNBUFFERED=1 \
LANG=C.UTF-8 \
DEBIAN_FRONTEND=noninteractive \
APP_PORT=8080
# Project setup
RUN mkdir -p /app/project
COPY . /app/project
WORKDIR /app/project
# Dependency installation
RUN pip install --upgrade pip \
&& pip install uwsgi \
&& pip install -r requirements.txt
# Service port declaration
EXPOSE 8080