
These days Docker is expected from backend, frontend and full stack developers too, not just DevOps engineers. This first DevOps set covers how images and containers work, how to write lean Dockerfiles, how to keep data safe with volumes, and how to run a few services together with Docker Compose.
How to practise: read each question and tap the option you think is correct. You will see right away whether you got it, along with a short explanation, and your score is tracked at the bottom of the screen. This set has 15 questions.
Topics covered in this set
- Images, containers and layers
- Build cache and instruction order
- CMD vs ENTRYPOINT, COPY vs ADD
- Multi-stage builds and .dockerignore
- Volumes, bind mounts, ports and networks
- Docker Compose and containers vs VMs
DevOps MCQs with answers and explanations
Q1. What is the relationship between a Docker image and a container?
a) A container is a compressed image file
b) They are two names for the same thing
c) An image runs inside a container
d) An image is a read-only template; a container is a running instance of it with its own writable layer
Q2. Why do Node.js Dockerfiles usually copy package.json and run npm install before copying the rest of the source code?
a) Because COPY . . cannot copy package.json
b) To make the image run faster at runtime
c) Because npm install must run as the first instruction
d) So the dependency layer stays cached and is rebuilt only when package files change
Q3. An image has CMD ["node", "server.js"] and no ENTRYPOINT. What happens with docker run myimg node worker.js?
a) It runs node worker.js, because arguments after the image name replace CMD
b) It runs node server.js node worker.js
c) It runs node server.js and ignores the arguments
d) The build fails
Q4. A Dockerfile contains:
ENTRYPOINT ["python", "app.py"] CMD ["--port", "8000"]What runs for
docker run myimg --port 9000?
a) python app.py --port 8000
b) python app.py --port 9000
c) --port 9000
d) python app.py --port 8000 --port 9000
Q5. What is the recommended difference in use between COPY and ADD?
a) ADD is faster, so it should always be used
b) COPY can download URLs and ADD cannot
c) There is no difference
d) Use COPY for plain local files; ADD also extracts local tar archives and can fetch URLs, so use it only when that is needed
Q6. What is the main benefit of a multi-stage build?
a) It runs several containers at once
b) The final image contains only the build output and runtime, not compilers, dev dependencies or source files
c) It removes the need for a base image
d) It builds images for every operating system
Q7. What is the key difference between a named volume and a bind mount?
a) Bind mounts are created with docker volume create
b) A named volume is managed by Docker in its own storage area; a bind mount maps a specific path from the host into the container
c) Volumes can only be read-only
d) Bind mounts are always faster
Q8. A PostgreSQL container writes its data to the container filesystem with no volume attached. What happens to the data when the container is removed with docker rm?
a) It is pushed to Docker Hub
b) It is lost, because the writable layer is deleted with the container
c) It is moved to a default volume
d) It is saved into the image automatically
Q9. Two containers are attached to the same user-defined bridge network. How can the api container reach the db container?
a) By using the container name, such as db, as the hostname, through Docker's built-in DNS
b) Only through the host's public IP
c) It is not possible without Kubernetes
d) By publishing every port on the host
Q10. In a docker-compose.yml, the api service needs to connect to a service named postgres. Which hostname should its database URL use?
a) host.docker.internal
b) 127.0.0.1
c) localhost
d) postgres
Q11. In Docker Compose, what does a plain depends_on: [db] guarantee for the api service?
a) Only that the db container is started before api, not that it is ready
b) That api restarts when db crashes
c) That the database is accepting connections before api starts
d) That both services share one container
Q12. What is the purpose of a .dockerignore file?
a) It ignores errors during the build
b) It excludes files such as node_modules, .git and .env from the build context sent to the Docker daemon
c) It lists images to delete
d) It hides running containers
Q13. How does a container mainly differ from a virtual machine?
a) Containers cannot run on Linux
b) Containers include a full guest operating system
c) Containers always need a hypervisor
d) Containers share the host kernel and isolate processes, so they start faster and use fewer resources than VMs
Q14. Why is the exec form CMD ["node", "server.js"] preferred over the shell form CMD node server.js?
a) The shell form cannot run Node.js
b) In exec form the app runs as PID 1 and receives signals such as SIGTERM directly, so it can shut down gracefully
c) The shell form is not allowed in Dockerfiles
d) Exec form images are always smaller
Q15. What does docker run -p 8080:80 nginx do?
a) Publishes container port 80 on host port 8080
b) Exposes port 80 only to other containers
c) Maps container port 8080 to host port 80
d) Runs nginx on both ports inside the container
Quick revision notes
- Image = read-only layers; container = running instance plus a writable layer.
- Order Dockerfile steps from least to most frequently changed to reuse the build cache.
- CMD is a default that docker run arguments replace. ENTRYPOINT stays fixed, and CMD becomes its arguments.
- Use volumes for data you want to keep and bind mounts for development. -p is host:container.
- Compose services reach each other by service name; depends_on does not wait for readiness.
Frequently asked questions
How can I make my Docker images smaller?
Start from a slim or Alpine base image and use multi-stage builds. Add a .dockerignore, install only production dependencies, and clean package caches in the same RUN step.
Should I run containers as root?
Try not to. Add a non-root user and switch to it with the USER instruction. Then, if someone breaks into the app, they get far fewer rights.
Is Docker Compose used in production?
It works well for local development, testing and small setups on one server. When you need many servers, scaling and self-healing, teams usually move to Kubernetes or a managed container service.
Comments
Post a Comment