Dockerfile instruction sets¶
A Dockerfile is a text document used to build Docker images automatically, containing all the commands a user could call on the command line to assemble an image^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md]. It defines the environment and dependencies required for an application to run, ensuring consistency across different deployment stages^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].
Core Instructions¶
Dockerfiles utilize a specific set of instructions to orchestrate the image creation process^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].
Image Foundation and Metadata¶
- FROM: Specifies the base image to build upon^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].
- USER: Sets the user name (or UID) to use when running the image^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].
- WORKDIR: Sets the working directory for any
RUN,CMD,ENTRYPOINT,COPY, andADDinstructions that follow^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md]. - EXPOSE: Informs Docker that the container listens on the specified network ports at runtime^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].
Environment and Execution¶
- ENV: Sets environment variables^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md]. These can be used by subsequent instructions or referenced in scripts.
- RUN: Executes commands in a new layer on top of the current image and commits the results^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md]. Commonly used for installing packages (e.g.,
yum install). - CMD: Provides the default command to execute when running the container^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md]. If the container is started without specific arguments, this command runs.
- ENTRYPOINT: Allows you to configure a container that will run as an executable^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].
File Management¶
- ADD: Copies files, directories, or remote file URLs from the source location and adds them to the filesystem of the image at the destination path^[400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md].
Related Concepts¶
- [[Docker]]
- [[Containerization]]
Sources¶
- 400-devops__06-Kubernetes__k8s-paas__01.Docker(已熟悉的可以从第二章开始).md