🐳 Docker — interview questions
11 questions. Filter by what the role asks for; open one for the six layers of the answer. The course is where the answers come from.
11 of 11
01A Dockerfile copies the whole repository, then runs `./mvnw package`, and every build re-downloads every dependency even when only a controller class changed. A teammate says "just add more RAM to the build machine." What's actually wrong, and what's the fix?Images and layerseasy0-2y02A service's production image is built `FROM eclipse-temurin:21-jdk`, includes Maven's full dependency cache, and is 850 MB. What's wrong with shipping that image, and what does a multi-stage build actually change?Images and layerseasy0-2y03A Spring Boot container is configured with `SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/orders`, and the database is a sibling container in the same Compose file. The application can't connect. Why not, and what should the URL say instead?Networkingeasy0-2y04A Spring Boot container is given a 1 GiB memory limit with no `-Xmx` or `-XX:MaxRAMPercentage` flag set, on a current JDK. It runs fine under light load, then gets killed under a traffic spike with no exception in the application log. What happened, and what's the fix?Java in a containermedium3-5y05A service is deployed with `cpu: 500m` (half a core). Its `newFixedThreadPool(Runtime.getRuntime().availableProcessors())` ends up with exactly one thread, and throughput is much worse than expected. What is `availableProcessors()` actually returning here, and why?Java in a containermedium3-5y06A Compose file has `depends_on: [postgres]` with no `condition:`, and the API container crashes on startup roughly one time in five with a connection-refused error, but never on a rerun a moment later. What's the race, and what actually fixes it?Composemedium3-5y07A Dockerfile downloads a large tarball, extracts it, and then `rm -rf`s the tarball and the extraction directory in a later `RUN`. The image is still just as large as if the cleanup never happened. Why doesn't the delete shrink the image, and what actually would?Images and layershard5-8y08A service's Dockerfile ends with `CMD java -jar app.jar` (shell form, no brackets). `docker stop` on the running container takes the full 10-second grace period every time, and the JVM never runs its shutdown hooks. What's actually happening, and what fixes it?Java in a containerhard5-8y09A service's image ends with `USER app` (uid 10001). In development it's run with `-v $(pwd)/data:/app/data`, where `./data` was created by a plain `mkdir` as the developer's own user (uid 1000). The container gets `Permission denied` writing to `/app/data`. Why, precisely, and does switching to a named volume change anything?Volumeshard5-8y10A team migrates a service onto a base image built on `eclipse-temurin:8u181-jre` — a build that predates container awareness — inside a container with a 512 MiB memory limit, on a node with 64 GiB of physical RAM. No `-Xmx` or `-XX:MaxRAMPercentage` is set. It runs fine for days, then dies with `OOMKilled`. Why does it take days rather than failing immediately, and what's actually different from the same scenario on a current JDK?Java in a containersenior8+y11A team's Dockerfile does `COPY target/app.jar app.jar` as a single layer, and every deploy — even a one-line code change — pushes and pulls the full 45 MB jar to and from the registry. What does switching to Spring Boot's layered jar actually change at the registry and node level, and why doesn't the same benefit apply to the fat jar no matter how the Dockerfile is restructured around it?Java in a containersenior8+y