Docker Containers

  • Definition: A Docker container is a runnable instance of a Docker image. Containers are isolated environments that run applications with all their dependencies.
  • Usage: Containers are used to run applications in isolated environments. They can be started, stopped, and removed independently of each other.
  • Lifecycle: Containers are created from images using the docker run command. They can be started, stopped, restarted, and deleted as needed.

Certainly! Here is a short markdown note for Obsidian that explains the difference between bind mounts and named volumes in Docker:


Docker: Bind Mounts vs. Named Volumes

Bind Mounts

Description

  • Bind mounts link a directory or file from the host filesystem into the container.
  • Useful for development purposes, where changes in your local filesystem should be reflected in the container instantly.

Characteristics

  • Direct Path Mapping: Directly reference a path on the host machine.
  • Real-Time Sync: Changes on the host are immediately reflected inside the container.
  • No Definition Needed: Does not need to be defined in the volumes section of docker-compose.yml.

Named Volumes

Description

  • Named volumes are managed by Docker and stored in a Docker-managed location on the host.
  • Useful for persisting data beyond the lifecycle of a single container.

Characteristics

  • Docker-Managed Storage: Stored in Docker-specific locations (e.g., /var/lib/docker/volumes/ on Linux).
  • Persistence: Data remains intact even if containers are removed.
  • Definition Required: Must be defined in the volumes section of docker-compose.yml.

Key Differences

  • Bind Mounts:

    • Ideal for development environments.
    • Direct path mapping from host to container.
    • No need for explicit volume definition.
  • Named Volumes:

    • Ideal for persisting data.
    • Managed by Docker.
    • Requires explicit volume definition for clarity and management.

Summary

  • Use bind mounts for development to reflect changes in real-time.
  • Use named volumes for data persistence and better management by Docker.

Comparison

FeatureDocker ImagesDocker VolumesDocker Containers
PurposeBlueprint for containersPersistent storage for container dataRunning instances of images
MutableNo (immutable once created)Yes (data can be changed)Yes (state changes during runtime)
CreationBuilt from DockerfilesCreated via Docker CLI or Docker ComposeCreated from Docker images
StorageStored in image registries (e.g., Docker Hub)Stored on host filesystemExist in memory and disk as long as running
IsolationProvides consistent environmentShares data across containers and hostIsolated environment for application
UsageBasis for creating containersPersistent data storageRun applications in isolated environments

Summary

  • Docker Images are the templates used to create containers.
  • Docker Volumes provide persistent storage that can be shared between containers and the host.
  • Docker Containers are the running instances of Docker images that execute applications in isolated environments.