Using `docker build` to create images and `docker run` with common flags.
Once you have a Dockerfile, the `docker build` command is used to construct the image. The basic syntax is `docker build [OPTIONS] PATH`. The `PATH` specifies the build context—the set of files at the specified location that can be used during the build process. A crucial option is `-t` (or `--tag`), which allows you to name and tag your image in a `name:tag` format, such as `my-app:1.0`. Tagging is essential for versioning and managing images. After a successful build, the image is stored locally. To bring this image to life, you use the `docker run` command. This command creates a new container from the specified image and starts it. The `docker run` command has numerous powerful flags. For instance, `-d` runs the container in detached mode (in the background). The `-p` (or `--publish`) flag maps a port from the host to the container (e.g., `-p 8080:80`), allowing you to access the containerized application from your local machine. The `--name` flag assigns a custom name to your container for easy reference. You can also use `-it` for an interactive terminal session inside the container (`-i` for interactive, `-t` for a pseudo-TTY). Mastering `docker build` and `docker run` is the core workflow for any Docker user, enabling the full cycle from source code to a running application.