For IT professionals
Lesson 04 of 5
About 11 minutes

Authorized DevOps and container security practice

Ask Gemini for a bounded Dockerfile review

Use Gemini to propose defensive edits to an authorized, sanitized Dockerfile, then verify each suggestion against the actual image.

Learning objective

Prompt Gemini to identify evidence-backed container improvements while retaining human review, scope boundaries, and build validation.

Use only a repository, branch, runner, registry, image, and activity you own or have explicit authorization to review. Use a Gemini tool only with sanitized material your organization approves. The website does not connect to Gemini.

Harden the image you actually ship

Review the final runtime stage, not just the builder stage. Choose a maintained base image that your organization trusts and that fits the application’s operating system, architecture, and native packages. For a release, confirm the source and supported version, then use the registry and digest policy approved by your organization. A small image is not automatically a trusted image.

Use a multi-stage build when build tools are not needed at runtime, copy only the required runtime files, and set USER to a non-root UID and GID. Confirm the application can read its files and write only to approved paths when running as that identity. Inspect the image configuration and execute a harmless identity check against the built image; seeing USER in source alone does not prove the launched image uses it.

Keep credentials out of the build context, Dockerfile, image layers, and logs. Do not pass secrets through ARG or ENV. Add local environment files and version-control metadata to .dockerignore. If an authorized build genuinely needs a private package credential, use a BuildKit secret mount and confirm the secret is not copied into the final image or its history.

Give Gemini only approved, sanitized material

Use Gemini only when your organization approves that tool for the material. Prefer a synthetic training Dockerfile or a sanitized copy of the exact authorized file. Remove credentials, private registry tokens, personal data, customer code, and internal hostnames unless policy explicitly permits sending them. This website provides prompts for learners; it does not connect to Gemini, send files, or supply Gemini credentials.

Make the prompt name the allowed assets, request line-level evidence, separate observed facts from assumptions, and ask for a verification command and compatibility check for each proposed fix. Ask Gemini to identify missing information rather than inventing a base-image digest or claiming a scan succeeded.

Review each suggestion against the actual Dockerfile, approved base-image source, CI configuration, image inspect output, and scanner report. Reject or revise suggestions that break the application, expand scope, add unapproved dependencies, or cannot be verified. A model answer is a proposal, not a security result.

Controlled examples

Adapt examples only inside your approved project

Controlled multi-stage Node image with a non-root runtimeThis is a controlled Node training example. Check that the approved base image supports the project’s runtime and dependencies; replace the example tag with the version and digest required by your organization. Confirm the real build output path, runtime package requirements, ownership, and start command before using it. The final stage names a non-root identity, but validate the effective user in the built image.
# syntax=docker/dockerfile:1
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:22-alpine AS runtime
ENV NODE_ENV=production
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY --from=build --chown=10001:10001 /app/dist ./dist
USER 10001:10001
CMD ["node", "dist/server.js"]
Training .dockerignore boundaryAdapt the ignore list to the approved project. Do not exclude files the build needs, and do not treat .dockerignore alone as proof that the final image contains no secret: inspect the build steps, layers, configuration, and scan results as well.
.git
.env
.env.*
node_modules
coverage
dist
Bounded prompt for an approved Gemini reviewReplace the bracketed parts only with material that your organization has approved for the selected Gemini tool. Keep the authorization statement truthful and specific. Do not paste real credentials or restricted source material.
I own this training repository or have written authorization for this exact repository and image.
Review only the sanitized Dockerfile and findings pasted below. Do not expand scope, access another asset, request credentials, or execute a change.
For every proposed container fix:
- Cite the exact Dockerfile line or supplied finding that supports it.
- Separate observed evidence from assumptions and name missing information.
- Suggest the smallest compatible change and an independent verification command.
- Check for an approved maintained minimal base image, non-root runtime execution, and secrets excluded from the build context, layers, image configuration, and logs.
- Do not invent a digest, vulnerability result, or successful test.
Return a short table with: evidence, risk or uncertainty, proposed fix, and verification.

Sanitized Dockerfile:
[paste only approved lines]

Sanitized scan findings:
[paste only approved finding fields]

Controlled practice

Apply the lesson

Training scenario

A controlled training image runs as root, copies the whole build context, and uses the same broad stage for building and runtime. The exercise includes no customer code, live credentials, or production image.

  1. Confirm ownership or written authorization for the exact training repository, Dockerfile, image, and review activity.
  2. Review .dockerignore, builder/runtime separation, the approved base-image source, runtime USER, COPY ownership, and secret paths.
  3. Paste only sanitized, approved training material into the prompt above and ask Gemini for line-level proposals plus verification commands.
  4. Check each proposal against the real files and project constraints. Reject unverified claims and changes that broaden the exercise.
  5. Build the image in the approved environment, inspect its base and configured user, and confirm the application works without adding secrets to the image.

Check your work: The reviewed image uses an organization-approved maintained base, starts under a verified non-root identity, excludes credentials from the context and image, and still passes the project’s actual build and runtime checks.

Learning check

Check your understanding

Gemini recommends a new base image and says the non-root change is safe. What is the next responsible step?

Choose the best answer

Official references

Continue in the lesson sequence. Return to the GitLab and Gemini path.