Build context and Dockerfile instructions
The build context supplies files accessible to COPY and related build operations. FROM selects a base, WORKDIR sets a working directory, COPY adds files, and RUN performs build-time work. CMD defines default runtime behavior. These instructions operate at different phases and should not be confused. For example, cOPY app.py /app/app.py occurs during build; CMD ["python","/app/app.py"] is the default process at container start.
COPY app.py /app/app.py occurs during build; CMD ["python","/app/app.py"] is the default process at container start.
A build starts with the chosen context directory. FROM selects the initial image, WORKDIR selects the working location for subsequent instructions, COPY transfers eligible context files, and RUN executes build-time commands. When a container later starts, CMD supplies its default runtime command unless launch settings override it. Build success and startup success are separate stages.
The build context is the set of files available to relevant build operations. An instruction defines one operation. Runtime begins when a container starts from the resulting image. A file outside the context is not available merely because it exists elsewhere on the developer's laptop. Moving a command between RUN and CMD changes when and how often it executes. Keep the main runtime process in the foreground so its exit reflects container lifecycle. A server started only during image building is not a running server in the final container.
COPY app.py /app/app.py occurs during build; CMD ["python","/app/app.py"] is the default process at container start.
Do not overlook this operational distinction: These instructions operate at different phases and should not be confused.