Docker - Interview preparation guide
Thilan Dissanayaka Interview Guides Mar 24, 2020

Docker - Interview preparation guide

What is Docker and why is it used?

Docker is a platform for developing, shipping, and running applications in containers. Containers package an application with its dependencies, ensuring consistency across environments. Docker simplifies:

  • Application deployment
  • Environment management
  • Scalability
  • Isolation

What is the difference between a container and a virtual machine?

  • Containers share the host OS kernel and run as isolated processes. They are lightweight and start quickly.
  • VMs include a full OS with their own kernel, making them heavier and slower to boot.
  • Containers are more efficient in terms of resource usage compared to VMs.

What is a Dockerfile?

A Dockerfile is a script containing a set of instructions to build a Docker image. Common commands include:

  • FROM – Base image
  • RUN – Execute a command
  • COPY / ADD – Copy files into the image
  • CMD / ENTRYPOINT – Define default container behavior

What is the difference between CMD and ENTRYPOINT in a Dockerfile?

CMD Purpose: Provides default arguments to the container.

Overridable?: Yes, easily overridden when you run the container using docker run ... [args].

Example:

FROM ubuntu
CMD [\"echo\", \"Hello from CMD\"]

If you run:

docker run myimage

→ Output: Hello from CMD

But if you run:

docker run myimage echo \"Hi there\"

→ Output: Hi there 👉 CMD was completely replaced by what you passed in the docker run command.

🔹 ENTRYPOINT Purpose: Defines the main executable that always runs.

Overridable?: Not overridden easily by default args. It runs unless you use --entrypoint explicitly.

Example:

FROM ubuntu
ENTRYPOINT [\"echo\"]
CMD [\"Hello from CMD\"]

Now, if you run:

docker run myimage

→ Output: Hello from CMD Because this expands to: echo Hello from CMD

If you run:

docker run myimage \"Hi there\"`

→ Output: Hi there It becomes: echo Hi there

The ENTRYPOINT remains; only the arguments (from CMD or command line) change.

To override ENTRYPOINT, you must explicitly use --entrypoint:

docker run --entrypoint /bin/bash myimage

Using Them Together This is the most flexible and common usage:

ENTRYPOINT: defines the fixed command

CMD: defines default arguments, which can be overridden.

Example:

FROM ubuntu
ENTRYPOINT [\"ping\"]
CMD [\"localhost\"]

Default run:

docker run myimage

→ Runs: ping localhost

Override CMD:

docker run myimage 8.8.8.8

→ Runs: ping 8.8.8.8

How does Docker networking work?

Docker provides several network drivers:

  • bridge (default) – containers on the same host can communicate
  • host – shares the host’s network stack
  • overlay – used in Docker Swarm for multi-host communication
  • none – disables networking

You can also create custom user-defined bridges for container communication by name.

What is the difference between an image and a container?

  • Image: A read-only template used to create containers.
  • Container: A runnable instance of an image, which is isolated and can have its own file system and processes.

How do you manage data in Docker containers?

  • Use volumes and bind mounts:
    Volumes are managed by Docker and stored in a special location (/var/lib/docker/volumes).

  • Bind mounts map directories from the host system into the container.
    They help in persisting data and sharing between containers.

What is a multi-stage build in Docker?

Multi-stage builds allow you to use multiple FROM statements to build and copy only the necessary artifacts into the final image. This reduces the image size and separates build dependencies from runtime.

How do you reduce the size of a Docker image?

  • Use minimal base images (like alpine)
  • Remove unnecessary files after installation
  • Combine RUN statements to reduce layers
  • Use .dockerignore to exclude files from the build context
  • Apply multi-stage builds

How do you update a running Docker container?

You can’t directly update a running container. Instead:

  • Stop and remove the old container
  • Build or pull a new image
  • Run a new container with the updated image

Docker containers are meant to be immutable and replaced, not patched.

What are Docker Compose and its benefits?

Docker Compose is a tool for defining and running multi-container Docker applications using a docker-compose.yml file. Benefits:

  • Easier to define complex applications
  • Simple multi-container orchestration
  • Unified configuration for services, volumes, and networks
version: \"3\"
services:
  web:
    image: nginx
    ports:
      - \"8080:80\"
  db:
    image: postgres
    environment:
      POSTGRES_PASSWORD: example
docker-compose up
ALSO READ
Remote Code Execution (RCE)
Jan 02 Application Security

Remote Code Execution (RCE) is the holy grail of application security vulnerabilities. It allows an attacker to execute arbitrary code on a remote server — and the consequences are as bad as it sounds. In this post, we'll go deep into RCE across multiple languages, including PHP, Java, Python, and Node.js.

Basic concepts of Cryptography
Mar 01 Cryptography

Ever notice that little padlock icon in your browser's address bar? That's cryptography working silently in the background, protecting everything you do online. Whether you're sending an email,...

Exploiting a format string vulnerebility on Linux
Apr 12 Exploit development

A misused printf can leak stack contents, read arbitrary memory, and write to arbitrary addresses. Format string vulnerabilities are one of the most powerful bug classes in C and they're the key to defeating ASLR. In this post, we exploit printf from leak to shell.

Boolean Based Blind SQL Injection
Feb 12 Application Security

In regular SQL injection, you can see the database output right there on the page. Blind SQL injection is different — the application gives you nothing. No errors, no data, no feedback. But with boolean-based blind SQLi, you can still extract the entire database — one true/false question at a time.

Out of Band SQL Injection
Feb 14 Application Security

Out of Band SQL Injection (OOB SQLi) is an advanced SQL injection technique where the attacker cannot retrieve data directly through the same communication channel used to send the injection payload....

Common Web Application Attacks
Feb 05 Application Security

Web applications are one of the most targeted surfaces by attackers. This is primarily because they are accessible over the internet, making them exposed and potentially vulnerable. Since these...