EXPOSE accepts multiple ports on one line separated by spaces; it does not require multiple EXPOSE lines.
Step 2: Validate other options
Ports do not need quotes, EXPOSE is uppercase by convention, and commas are not used to separate ports.
Final Answer:
EXPOSE cannot list multiple ports on one line -> Option D
Quick Check:
One port per EXPOSE line only [OK]
Hint: Use one EXPOSE per port, no spaces or commas [OK]
Common Mistakes:
Listing multiple ports on one EXPOSE line
Adding quotes around port numbers
Writing EXPOSE in lowercase
5. You want to run a web app container that listens on port 3000 inside the container. You want to access it on port 8080 on your host machine. Which Docker commands and Dockerfile instructions correctly achieve this?
hard
A. Dockerfile: EXPOSE 8080 Run: docker run -p 3000:8080 image
B. Dockerfile: EXPOSE 3000 Run: docker run -p 8080:3000 image
C. Dockerfile: EXPOSE 3000 8080 Run: docker run -p 3000:8080 image
D. Dockerfile: EXPOSE 8080 Run: docker run -p 8080:8080 image
Solution
Step 1: Understand EXPOSE and port mapping
EXPOSE should list the internal container port (3000). The run command maps host port 8080 to container port 3000.
Step 2: Check each option's correctness
Dockerfile: EXPOSE 3000 Run: docker run -p 8080:3000 image correctly exposes 3000 and maps 8080 on host to 3000 in container. Others either reverse ports or use invalid EXPOSE syntax.
Final Answer:
Dockerfile: EXPOSE 3000 and run with -p 8080:3000 -> Option B