Understanding Docker, entrypoint.sh, and YAML When Creating a Container

If you are new to containers, words like Docker, entrypoint, and YAML can feel confusing.
This post explains them in simple English, using real-world examples.


1. What is Docker? (Think “boxed application”)

Docker is a way to package your application so it runs the same everywhere.

Imagine this:

  • Your app needs Linux
  • It needs certain tools (like MySQL client, curl, or Python)
  • It needs specific versions of those tools

Instead of installing everything manually on every machine, Docker lets you put everything into one box.

That box is called a container image.

In simple terms:

Docker = a way to ship your app + everything it needs, together.


2. What is a Dockerfile?

A Dockerfile is a text file that tells Docker how to build the box.

Example:

FROM debian:12-slim
RUN apt-get install -y curl
COPY app.sh /app/app.sh
ENTRYPOINT ["/app/app.sh"]

This says:

  1. Start with Linux (debian)
  2. Install some tools
  3. Copy your script into the container
  4. Decide what runs when the container starts

3. What is entrypoint.sh?

The short answer:

entrypoint.sh is the first thing that runs when the container starts.

Think of it like:

  • The main() function in a program
  • Or the power button of the container

If Docker is the box, then entrypoint.sh is:

“What should this box do when it turns on?”


Example entrypoint.sh

#!/usr/bin/env bash
echo "Hello from the container"

When the container starts, this script runs automatically.


Why use entrypoint.sh?

It lets you:

  • Run startup logic
  • Check environment variables
  • Start services
  • Run jobs (like backups or migrations)

For example:

#!/usr/bin/env bash

echo "Starting backup..."
mysqldump mydb > backup.sql

Every time the container runs, it does exactly this job.


4. What is YAML and why is it used?

YAML is just a configuration file format.

It is used to describe:

  • What container to run
  • How much CPU/memory to use
  • Environment variables
  • When the container should run

YAML does not run code.
It only describes settings.


5. YAML vs entrypoint.sh (very important difference)

FilePurpose
entrypoint.shWhat the container does
YAMLHow the container is configured

Example YAML (simplified)

containers:
  - image: myapp:1.0
    env:
      DB_HOST: localhost

This means:

  • Run image myapp:1.0
  • Pass DB_HOST into the container

Inside the container, entrypoint.sh can read that value.


6. How everything works together

Here’s the full flow:

  1. Dockerfile
    • Builds the container image
  2. entrypoint.sh
    • Runs when the container starts
    • Does the actual work
  3. YAML
    • Tells the platform how to run the container
    • Sets memory, environment variables, schedule, etc.

In one sentence:

Docker builds the box, YAML configures it, and entrypoint.sh does the work.


7. Real-world analogy

Think of a coffee machine:

  • Docker image → The coffee machine itself
  • YAML → Settings (water amount, strength, timer)
  • entrypoint.sh → The button that actually makes the coffee

You can change settings without rebuilding the machine, but the machine still needs a button to do something.


8. Why this separation is powerful

This design lets you:

  • Change configuration without changing code
  • Reuse the same image in dev, test, and prod
  • Debug problems easily
  • Run the same container locally and in the cloud

This is why containers are so popular in modern cloud systems.


Final takeaway

If you remember just one thing, remember this:

Docker builds the container, YAML configures it, and entrypoint.sh is what actually runs inside it.

Once this clicks, containers stop feeling complicated.

FavoriteLoadingAdd to favorites

RECENT POSTS


Categories



Tags

ADO ai angular asian asp.net asp.net core azure ACA azure administration Azure Cloud Architect Azure Key Vault Azure Storage Blazor WebAssembly BLOB bootstrap c# containers css datatables design pattern docker excel framework Git HTML JavaScript jQuery json knockout lab LINQ linux power bi powershell REST API smart home SQL Agent SQL server SSIS SSL SVG Icon typescript visual studio Web API window os wordpress


ARCHIVE


DISCLAIMER