Test your understanding of the concepts covered in the Webapps with Docker chapter.
Q1. In `docker run -p 8888:5000 myapp`, what does the port mapping `-p 8888:5000` specify?
Explanation
Syntax `-p [HOST_PORT]:[CONTAINER_PORT]` maps traffic arriving at port 8888 on your host machine to port 5000 inside the container.
Q2. Which Dockerfile instruction sets the base image for subsequent build instructions?
Explanation
The `FROM` instruction initializes a new build stage and specifies the base image (e.g. `python:3.12-slim`) upon which your image is constructed.
Q3. Why is it a best practice to copy `requirements.txt` and run `pip install` BEFORE copying the rest of your application code (`COPY . .`)?
Explanation
Docker caches each build step layer. By installing dependencies first, Docker reuses the cached `pip install` layer when only application source code changes.
Q4. What is the primary difference between `RUN` and `CMD` in a Dockerfile?
Explanation
`RUN` executes shell commands during `docker build` to construct image layers. `CMD` specifies the default command executed when running `docker run`.
Q5. When deploying a single-container application to AWS Elastic Beanstalk, what file is uploaded to configure image name and port mapping?
Explanation
`Dockerrun.aws.json` is the AWS-specific configuration file that tells Elastic Beanstalk which Docker image to pull and which ports to expose.