🐳 Docker Diaries: Your First Container — Step by Step

Docker Diaries: Your First Container — Let's familiar with docker

Hello again, friends! πŸ‘‹

In the last blog, we explored the magical world of containers. 🧳

Now it's time to get our hands a little dirty and actually build our very first container using Docker! 🚒

Whether you're a student, a developer, or just curious, this blog is your simple, no-jargon guide to Docker and container creation.

First Things First: What is Docker?

Let’s quickly recap:

Docker is a platform that helps you build, run, and manage containers.

Imagine Docker as a kitchen where you prepare your app (like a meal), pack it (in a box = container), and deliver it anywhere — whether it’s your laptop, server, or the cloud. 🍱


πŸ› ️ Step 1: Install Docker

Before you start, you need Docker installed on your system.

πŸ‘‰ For Windows or Mac:

πŸ‘‰ For Linux (Ubuntu):

bash

sudo apt update
sudo apt install docker.io sudo systemctl start docker sudo systemctl enable docker

To confirm Docker is installed, run:

bash

docker --version

You should see something like:

Docker version 28.0.4, build b8034c0

✅ You’re ready to go now!

✍️ Step 2: Write Your First Dockerfile

Let’s containerize a simple app.
We’ll start with a basic Python app that prints “Hello from Docker!”.

πŸ—‚ Create a project folder:

mkdir docker-demo
cd docker-demo

πŸ“ Inside that folder, create a file called app.py:

print("Namaste! from Docker!")

πŸ“¦ Now, create a file named Dockerfile (no file extension):

Dockerfile

# Use an official Python base image FROM python:3.10 # Set the working directory inside the container WORKDIR /app # Copy current files to the container COPY . . # Command to run when the container starts CMD ["python", "app.py"]

Step 3: Build Your Docker Image

A Docker image is like a blueprint of your application.

Run this in your terminal (inside the docker-demo folder):

bash


docker build -t my-first-container .

What’s happening?

  • -t gives it a tag (name).

  • . tells Docker to use the current directory.

After a few seconds, your image will be ready! CongratsπŸŽ‰

Step 4: Run Your Container

Let’s see the magic!

bash

docker run my-first-container

You should see this output:

csharp

Hello from Docker!

πŸ₯³ Congrats! You just created and ran your first Docker container!

🧽 Step 5: Clean Up (Best Practice!)

As you work with Docker, your system can fill up with unused containers and images.

Here are a few handy clean-up commands:

  • List all containers:

    bash

    docker ps -a
  • Remove a container:

    bash

    docker rm <container_id>
  • Remove an image:

    bash

    docker rmi <image_id>
  • Remove all stopped containers and unused images:

    bash

    docker system prune

πŸ’‘ Tip: Always clean up regularly to save space and avoid confusion.


Best Practices for Docker Beginners

  1. Keep Dockerfiles simple – Avoid unnecessary layers.

  2. Use .dockerignore – Like .gitignore, to avoid copying unwanted files.

  3. Pin your base image versions – Example: python:3.10, not just python.

  4. Don’t run as root inside containers – It’s safer to create a user.

  5. Keep your images small – Clean up unnecessary files during build.

What’s Next?

Now that you’ve built your first container, you’re ready to explore:

  • Docker Compose (to manage multi-container apps)

  • Docker Hub (to share your containers)

  • And eventually, Kubernetes (to manage lots of containers!)

 So,

Learning Docker is like learning to pack smart — it makes your apps organized, portable, and ready to travel. ✈️

Try this out and let me know how your first Docker experience goes!
If you’re stuck or curious, just drop a comment. I’ve got your back. πŸ’ͺ


Comments

Popular among the all

While Building a Real-Time Game: Why a Single Stable Port Matters More Than You Think

Container Chronicles(In hindi we refers as Container ki ΰ€•ΰ€₯ा): Exploring Containers and Beyond

Web Application-Threats and Security