FROM)MAINTAINER, LABEL)apt-get install, apk add)bower.json, package.json, build.gradle, requirements.txt)npm install, pip install)CMD, ENTRYPOINT, ENV, EXPOSE)These orderings are made for optimizing build time using Docker's built-in caching mechanism.
Rule of thumbs:
Parts that change often (e.g. codebase) should be placed near bottom of Dockerfile, and vice-versa. Parts that rarely change (e.g. dependencies) should be placed at top.
# Base image
FROM python:2.7-alpine
# Metadata
MAINTAINER John Doe <johndoe@example.com>
# System-level dependencies
RUN apk add --update \
ca-certificates \
&& update-ca-certificates \
&& rm -rf /var/cache/apk/*
# App dependencies
COPY requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
# App codebase
WORKDIR /app
COPY . ./
# Configs
ENV DEBUG true
EXPOSE 5000
CMD ["python", "app.py"]
MAINTAINER will be deprecated in Docker 1.13, and should be replaced by using LABEL. (Source)
Example: LABEL Maintainer="John Doe johndoe@example.com"