Docker and CI/CD Junior interview questions and answers

75 questions for a Docker and CI/CD (Junior) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.How does a container differ from a virtual machine?
  2. 2.What is the difference between an image and a container?
  3. 3.What is a Dockerfile?
  4. 4.What does FROM node:22-alpine do in a Dockerfile?
  5. 5.What is the difference between RUN and CMD?
  6. 6.How does ENTRYPOINT relate to CMD?
  7. 7.Why is COPY usually preferred over ADD?
  8. 8.What does WORKDIR /app do?
  9. 9.Does EXPOSE 3000 in a Dockerfile make the port reachable from the host?
  10. 10.What does docker run -p 8080:3000 my-app mean?
  11. 11.How do you see stopped containers as well as running ones?
  12. 12.How do you read the output of a running container?
  13. 13.How do you open a shell inside a running container?
  14. 14.Why does a container exit right after starting?
  15. 15.What happens to files written inside a container when you remove it?
  16. 16.What is the difference between a volume and a bind mount?
  17. 17.What is .dockerignore for?
  18. 18.Why copy package.json and the lockfile before the rest of the source code?
  19. 19.What does the latest tag mean?
  20. 20.In docker build -t my-app ., what is the .?
  21. 21.What is a container registry?
  22. 22.What is the difference between ARG and ENV?
  23. 23.What is Docker Compose used for?
  24. 24.In Compose, how does the app service connect to the db service?
  25. 25.Does depends_on: [db] wait until the database is ready to accept connections?
  26. 26.What does docker compose down -v do in addition to down?
  27. 27.Inside a container, what does localhost refer to?
  28. 28.What does docker stop do?
  29. 29.What is the difference between docker rm and docker rmi?
  30. 30.Your disk is full of old Docker data. What is a common cleanup command?
  31. 31.How do you pass an environment variable when starting a container?
  32. 32.What does --rm do in docker run --rm my-app?
  33. 33.What is a common gotcha with Alpine-based images?
  34. 34.Why shouldn't you copy a .env file with secrets into an image?
  35. 35.What does -d do in docker run -d nginx?
  36. 36.What do the -it flags give you?
  37. 37.What does --restart unless-stopped do?
  38. 38.What does a HEALTHCHECK instruction add to a container?
  39. 39.What is Continuous Integration (CI)?
  40. 40.What is the difference between continuous delivery and continuous deployment?
  41. 41.What does a typical CI/CD pipeline do, in order?
  42. 42.Why run CI on every pull request?
  43. 43.Where do GitHub Actions workflow files live?
  44. 44.In GitHub Actions, what is the difference between a job and a step?
  45. 45.What does runs-on: ubuntu-latest set?
  46. 46.What does the step uses: actions/checkout@v4 do?
  47. 47.What does on: [push, pull_request] define in a workflow?
  48. 48.How should a workflow access an API token for deployment?
  49. 49.Why use npm ci rather than npm install in CI?
  50. 50.What does caching dependencies in CI speed up?
  51. 51.What are workflow artifacts?
  52. 52.What happens by default when a step in a job fails?
  53. 53.How do you make a deploy job wait for the test job?
  54. 54.What does a build matrix do?
  55. 55.Which file configures GitLab CI/CD?
  56. 56.Why keep configuration such as database URLs in environment variables?
  57. 57.What is a staging environment for?
  58. 58.What is a rollback?
  59. 59.What is blue-green deployment?
  60. 60.What does "build once, deploy many" mean?
  61. 61.Why pin FROM node:22.11-slim instead of FROM node?
  62. 62.Why does image size matter?
  63. 63.Should the .env file with local secrets be committed to Git?
  64. 64.What is a required status check?
  65. 65.What is a flaky test?
  66. 66.How can a pipeline deploy only released versions?
  67. 67.Which user does a container's process run as by default?
  68. 68.What does docker inspect <container> show?
  69. 69.Why can't two containers on the default bridge reach each other by name?
  70. 70.How do you follow logs from all services in a Compose project?
  71. 71.docker run -p 5432:5432 postgres fails with "port is already allocated". Why?
  72. 72.How are an image's layers and a container's changes stored?
  73. 73.How does Docker Desktop run Linux containers on macOS or Windows?
  74. 74.What does docker build --no-cache do?
  75. 75.What does docker compose up --build add to up?