Skip to main content
junior
beginner
Docker

Docker Container Basics

Question

What is the difference between a Docker image and a container? How do they relate to each other?

Answer

A Docker image is a read-only template containing application code, dependencies, and configuration. A container is a running instance of an image. You can create multiple containers from one image. Images are built from Dockerfiles and stored in registries. Containers are ephemeral - they can be started, stopped, and destroyed.

Why This Matters

Understanding the image/container distinction is fundamental to Docker. Think of an image as a class definition and a container as an object instance. This relationship enables consistent deployments across environments - the same image produces identical containers everywhere.

Code Examples

Working with images and containers

bash

Simple Dockerfile

dockerfile
Common Mistakes
  • Confusing images with containers
  • Not cleaning up stopped containers and unused images (disk space issues)
  • Running containers as root without considering security implications
Follow-up Questions
Interviewers often ask these as follow-up questions
  • What happens to data inside a container when it stops?
  • How do you persist data using Docker volumes?
  • What is the difference between docker run and docker start?
Tags
docker
containers
images
fundamentals