A new developer needs your application, its language runtime, and the right dependencies. A Dockerfile puts the steps for assembling that environment in one place instead of leaving them in setup notes or someone’s memory. Docker uses those instructions to build a container image that others can build and run. section 2.0 section 2.1.3
Think of a Dockerfile as a short procedure for preparing an image. Start from a base image, then add what the application needs. The resulting container keeps its dependencies separate from other applications on the same host, making local development and deployment more reproducible. section 1.1.1 section 2.1.3
Listing 2.2 Chapter02/2.1.3_Dockerfile/Dockerfile
FROM ubuntu #1 RUN apt-get update #2 RUN apt-get install -y python3 #2 COPY . /app #3 WORKDIR /app #4
This Python example starts with Ubuntu, installs Python 3, copies the application into /app, and sets /app as the working directory. section 2.1.3
From the Dockerfile’s directory, `docker build . -t hello` builds the image. The example runs it with `docker run hello python3 hello.py`. Building the image and running the program are separate steps; the run command supplies the Python command in this example. section 2.1.3
For a compiled application, copying source files is not enough unless they have already been compiled. A Dockerfile can perform that work during the build. The Java example starts from OpenJDK, copies the source, sets a working directory, compiles with `RUN javac Hello.java`, and specifies `CMD java Hello` for execution. Multistage builds can separate the environment used to build a program from the one used to run it. section 2.1.7 section 2.4
Listing 2.12 Chapter02/2.1.7_CompiledCode/Dockerfile
FROM openjdk COPY . /app WORKDIR /app RUN javac Hello.java #1 CMD java Hello #1 The compile command
Compare this Java Dockerfile with the Python one: its RUN instruction compiles source code, while CMD names the command used to run the application. section 2.1.7

















