π³ 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:
-
Download Docker Desktop and follow the installation steps.
π For Linux (Ubuntu):
To confirm Docker is installed, run:
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:
π Inside that folder, create a file called app.py:
π¦ Now, create a file named Dockerfile (no file extension):
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):
What’s happening?
-
-tgives 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!
You should see this output:
π₯³ 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:
-
Remove a container:
-
Remove an image:
-
Remove all stopped containers and unused images:
π‘ Tip: Always clean up regularly to save space and avoid confusion.
✅ Best Practices for Docker Beginners
-
Keep Dockerfiles simple – Avoid unnecessary layers.
-
Use .dockerignore – Like
.gitignore, to avoid copying unwanted files. -
Pin your base image versions – Example:
python:3.10, not justpython. -
Don’t run as root inside containers – It’s safer to create a user.
-
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
Post a Comment