Docker Container Basics
What is the difference between a Docker image and a container? How do they relate to each other?
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.
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.
Working with images and containers
Simple Dockerfile
- Confusing images with containers
- Not cleaning up stopped containers and unused images (disk space issues)
- Running containers as root without considering security implications
- 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?