DEV Community

Cover image for Docker and volumes, EBS, kubernetes
Mohammed
Mohammed

Posted on

Docker and volumes, EBS, kubernetes

Docker Fundamentals 🐳

Docker is an open-source platform that makes it easy to build, ship, and run applications in isolated environments called containers.

  • A Dockerfile is a plain text file that contains a set of instructions (like FROM, WORKDIR, COPY, RUN, EXPOSE, CMD) that Docker reads to build a Docker image. It's essentially a recipe for your application's environment.

  • A Docker image is a lightweight, standalone, executable package that includes everything needed to run an application: code, runtime, system tools, libraries, and settings. Images are read-only.

  • A Docker container is a runnable instance of a Docker image.5 You can create, start, stop, move, or delete containers using Docker commands.

Core Docker Workflow

  1. Build the Image: After creating your Dockerfile (e.g., for a Streamlit app with app.py and requirements.txt), you build the image using: Bash

docker build -t my_image .

The -t flag tags the image with a name, and . specifies the current directory as the build context.

  1. Run the Container: Once the image is built, you run a container from it. Critically, for web applications like Streamlit, you must include port mapping to make the container's port accessible from your host machine: Bash

    docker run -p <host-port>:<container-port> <your-image-name>

    For a Streamlit app, this would typically be docker run -p 8501:8501 my-streamlit-app, allowing you to access it via http://localhost:8501.


Container Ephemerality & Data Persistence

Containers are designed to be ephemeral; any data written directly inside a container's writable layer is lost when the container is stopped and deleted. This promotes disposability and immutability.

To persist data, Docker provides:

  • Volumes: The preferred method for persistent storage.10 Volumes are managed by Docker and exist independently of the container, storing data on the host machine or remote storage. They can be attached to new containers.

  • Bind Mounts: Allow you to mount a file or directory from the host machine's filesystem directly into a container. Useful for development or accessing host files.


Docker, Kubernetes, VMs, and Cloud Storage

  • Containers vs. VMs: Containers virtualize the operating system, sharing the host OS kernel, making them lighter and faster than Virtual Machines (VMs), which virtualize the entire hardware and include their own guest OS.

  • Kubernetes (K8s): An orchestration platform for automating the deployment, scaling, and management of containerized applications across multiple machines (Nodes). Kubernetes operates at the container/Pod level, deciding where to run your application instances on available Nodes and managing their lifecycle.

  • Nodes: In Kubernetes, a Node is a worker machine (which can be a VM or a physical server) that provides the compute capacity for Pods. Kubernetes manages what runs on these Nodes and monitors their health.

  • Auto Scaling Groups (ASGs): These are cloud-provider specific features (like in AWS EC2) that focus on automatically scaling the number of VMs (instances) based on defined policies (e.g., CPU utilization). ASGs operate at the VM level, provisioning and maintaining the underlying machines.

  • Synergy: In the cloud, ASGs often provide the underlying pool of VMs that become Kubernetes Nodes.13 The Kubernetes Cluster Autoscaler can then interact with ASGs to dynamically adjust the number of Nodes based on the container (Pod) scheduling needs.

  • EBS (Amazon Elastic Block Store): This is a persistent block-level storage service in AWS that acts like a virtual hard drive for EC2 instances.14 When running stateful applications (like databases) in containers on Kubernetes on AWS.

EBS volumes are often used to back Docker volumes or Kubernetes Persistent Volumes to ensure data persistence even if containers or nodes are replaced.

In essence, Docker provides the container, Kubernetes orchestrates those containers across a cluster of VMs (Nodes), ASGs help scale the number of those VMs, and EBS provides the durable storage for persistent data.

Top comments (0)