🚀 Understanding the Docker Lifecycle with a Simple App
Latchu@DevOps

Latchu@DevOps @latchudevops

About: Infra. Automation. Impact

Location:
Chennai, India
Joined:
Apr 10, 2025

🚀 Understanding the Docker Lifecycle with a Simple App

Publish Date: Aug 9
7 2

Docker simplifies how we build, ship, and run applications by following a clear lifecycle.
Let’s break it down into three main stages with an easy-to-follow example using Ubuntu and a small Python app.


1️⃣ Create the Dockerfile

A Dockerfile is like a recipe for your application. It tells Docker:

  • Which base image to start from
  • What dependencies to install
  • What command to run when the container starts

Example:

# Start with an official Ubuntu image
FROM ubuntu:22.04

# Install Python
RUN apt-get update && apt-get install -y python3

# Copy our app to the container
COPY app.py /app/app.py

# Set working directory
WORKDIR /app

# Run the app when container starts
CMD ["python3", "app.py"]

Enter fullscreen mode Exit fullscreen mode

2️⃣ Build the Docker Image

The Dockerfile is just instructions. To actually create something runnable, we build an image:

Using the Dockerfile, a Docker image is created through the docker build command. A Docker image is a lightweight, standalone, and executable package that includes everything needed to run an application, such as the runtime environment, system tools, libraries, and dependencies.

docker build -t ubuntu-simple-app .

Enter fullscreen mode Exit fullscreen mode

What happens here?

  • Docker takes the Ubuntu image
  • Installs Python
  • Copies app.py into it
  • Creates a ready-to-use image named ubuntu-simple-app

3️⃣ Run the Docker Container

Once the image is built, a Docker container is created and executed using the docker run command. A container is an isolated environment where the application runs consistently across different systems. Containers leverage the lightweight nature of Docker images, ensuring minimal overhead and fast deployment.

docker run --name my-simple-app ubuntu-simple-app
Enter fullscreen mode Exit fullscreen mode

Example app (app.py):

print("Hello from inside my Ubuntu-based Docker container!")
Enter fullscreen mode Exit fullscreen mode

Output:

Hello from inside my Ubuntu-based Docker container!
Enter fullscreen mode Exit fullscreen mode

🔄 Quick Recap

  1. Dockerfile → Your recipe for building the image
  2. Build Image → Turn recipe into a runnable package
  3. Run Container → Launch the app in an isolated environment

By following this lifecycle, you ensure your app runs consistently anywhere — your laptop, a server, or the cloud.


💡 Pro Tip:

You can share your image with others via Docker Hub:

docker tag ubuntu-simple-app your-dockerhub-username/ubuntu-simple-app
docker push your-dockerhub-username/ubuntu-simple-app
Enter fullscreen mode Exit fullscreen mode

Comments 2 total

  • Vida Khoshpey
    Vida Khoshpey Aug 9, 2025

    Even though it's so hard for me but so cool 😎

    • Latchu@DevOps
      Latchu@DevOpsAug 11, 2025

      It is very essential to learn when Cloud and DevOps comes

Add comment