| # | Lines starting with '#' are comments, providing explanations or context for the Dockerfile. |
| `FROM` | Specifies the base image used to build the new image. In this case, it's using the official Python 3.8 slim image. |
| `WORKDIR` | Sets the working directory for any subsequent instructions in the Dockerfile. Here, it's set to '/app'. Everything after a `WORKDIR` line, all instructions will be executed in this directory. If it doesn't exist, Docker will create it. Can have multiple. |
| `COPY` | Copies files or directories from the source (in this case, the current directory) to the destination (in this case, '/app') within the Docker image. The source is the build context. We are copying from the build context to the container when we use this keyword. |
| `ADD` | Same as `COPY` but can be passed a tarball or a URL |
| `RUN` | Executes a command and commits the result as a new layer in the image. In this example, it installs packages specified in the 'requirements.txt' file using pip. |
| `EXPOSE` | Informs Docker that the container listens on the specified network ports at runtime. In this case, port 80. |
| `ENV` | Sets an environment variable in the image. In this example, the variable 'NAME' is set to 'World'. |
| `CMD` | Specifies the command to run when the container starts. Here, it runs 'app.py' using Python. Note that there can only be one CMD instruction in a Dockerfile. |
| `USER` | The default user will be `root`. This is not good for security. Have to choose a distribution image that allows you to change user. For example: `USER: nobody:nogroup`. Ubuntu allows for this. |
| `LABEL` | Metadata that you want to add to the image to be viewable when image is inspected, e.g. `LABEL maintainer=tactonbishop@gmail.com` |
### Another example
The following Dockerfile creates a frontend React application:
```Dockerfile
# Use the official Node.js image as the base image
FROM node:14-alpine
# Set the working directory to /app
WORKDIR /app
# Copy the package.json and package-lock.json files