Installing software inside a running container does not save those changes to its image. To make the setup repeatable, write a Dockerfile: a file of instructions that a container builder uses to create a new image. That image can then be run or shared. section 5.1.4 section 5.2 section 1.4
A first Dockerfile needs only a few instructions:
- FROM chooses a prebuilt image to start from. section 5.2.1
- RUN executes a build-time command, such as installing software. section 5.2.1
- CMD sets the command to run when the container starts. section 5.2.1
Listing 5.2 Your first Dockerfile
FROM ubuntu RUN apt-get update && apt-get install -y nginx CMD ["nginx", "-g", "daemon off;"]
The short NGINX Dockerfile starts from Ubuntu, installs NGINX, and sets its startup command. section 5.2.1
Build the NGINX image
From the Dockerfile's directory, run `docker build -t rk8s-nginx -f Dockerfile .`. The `-f` flag selects the Dockerfile; `-t` names the resulting image. section 5.2.1
Application Dockerfiles follow the same pattern with different contents. A Python example starts from `python:3.11.4`, copies source into `/app`, installs dependencies, and sets a server command. A Node.js example starts from `node:18.17.0`, copies source and package files, runs `npm install`, and starts an entrypoint script. section 5.3.2 section 5.4.2
Different environments can use different files: for example, `docker build -f Dockerfile.prod -t my-container:prod .` selects a production Dockerfile. A successful build is not proof that the application will run correctly, so build and run the image before relying on it. section 7.2.1 section 1.5

















