Skip to content

Day 8 - Quiz Solutions

Published:Β atΒ 12:00 AM

Hey everyone! These are the solutions for the quiz of the first week. Thank you for participating!

Q1: What is the main advantage of containers over virtual machines

A1: They are more lightweight by sharing the host’s kernel

Q2: Given this Dockerfile, what’s wrong with it?

FROM golang
WORKDIR /app
RUN go build -o main main.go
COPY . .
CMD ["./main"]

A2: Instructions are being run top to bottom. The COPY instruction is run after the RUN instruction, so the code to build the application is not available in the container. The build will fail.

Q3: Which command would correctly run a container and map port 3000 inside the container to port 8080 on your host machine?

A3: docker run -p 8080:3000 myapp

That was also a trick question. --port is wrong, because -p is the shorthand for --publish.

Q4: When you modify a file in a running container, the changes are automatically saved to the Docker image.

A4: False. The changes are not saved to the Docker image. They are saved to a temporary layer that is discarded after the container is stopped.

Q5: Which Dockerfile instruction does NOT create a new layer?

A5: CMD

Q6: Match the volume type with its use case

A6:

Q7: Write a Docker command that would 1. Create a container from image β€˜myapp’ 2. Mount a named volume called β€˜data’ to β€˜/app/data’ in the container 3. Run in detached mode 4. Map port 8080 to 8080

A7: docker run -d -v data:/app/data -p 8080:8080 myapp

If you have any questions, feel free to reach out to me on Twitter or by email at [email protected].

Until then, happy coding! πŸ³πŸŽ„

Jonas


Previous Post
Day 9 - Environment Variables & Configuration
Next Post
Day 10 - Docker Networking Basics
Sponsor logo

Sliplane

Deploy your Docker Apps straight from your Github repository in less than 2 minutes with sliplane.io

Learn More β†’