Skip to main content

Command Palette

Search for a command to run...

Docker + Django in 10 Days: From Zero to Production [Day: 02]

Published
β€’3 min read
Docker + Django in 10 Days: From Zero to Production [Day: 02]

🎯 Goal of Day 2

By the end of today, you will:

  • Clearly understand Images vs Containers (practically)

  • Run your first Docker container

  • Learn the most important Docker commands

  • See how Docker actually works on your machine

Today is hands-on, but still beginner-friendly.


πŸ” Quick Recap from Day 1 (30 seconds)

  • Image = blueprint 🧱

  • Container = running app πŸƒ

  • Dockerfile = recipe πŸ“œ

  • Docker = consistent environment everywhere

Keep this in mind as we move.


🧠 Image vs Container (Real Example)

Let’s say:

  • Image: python:3.12

  • Container: Python running in your terminal

You can:

  • Create 100 containers from 1 image

  • Delete containers β†’ image still stays


πŸš€ Your First Docker Command

Open your terminal and run:

docker run hello-world

What just happened?

Docker did this automatically:

  1. Looked for hello-world image locally

  2. Didn’t find it

  3. Downloaded it from Docker Hub

  4. Created a container

  5. Ran it

  6. Printed a message

  7. Exited

πŸŽ‰ Congrats β€” you just ran your first container


🌍 Docker Hub (Very Important)

Docker Hub is like GitHub for Docker images

Website:
https://hub.docker.com/

Examples:

  • python

  • postgres

  • redis

  • nginx

You’ll use these a LOT in Django-DRF.


πŸ§ͺ Running a Real Container (Python Example)

Run this:

docker run -it python:3.12

What this means:

  • -it β†’ interactive terminal

  • python:3.12 β†’ image name + version

You’ll enter a Python shell inside a container 🐍

Try inside it:

print("Hello from Docker")

Exit Python:

exit()

Exit container:

exit

πŸ“¦ Important Docker Commands (Must Know)

πŸ” See Images

docker images

πŸ” See Running Containers

docker ps

πŸ” See All Containers (even stopped)

docker ps -a

▢️ Run a Container

docker run image_name

Example:

docker run python:3.12

πŸ›‘ Stop a Running Container

docker stop <container_id>

❌ Remove a Container

docker rm <container_id>

❌ Remove an Image

docker rmi <image_id>

⚠️ You must stop & remove containers first.


🧠 Very Important Concept: Containers Are Ephemeral

When a container stops, its data is gone (by default).

Example:

  • You install something inside container

  • Stop it

  • Run a new container

  • It’s clean again

πŸ“Œ Solution (later days):

  • Volumes

  • Bind mounts


🧩 How This Relates to Django-DRF

In Django terms:

  • Image β†’ Django app template

  • Container β†’ Running Django server

  • Rebuild image β†’ Code/environment changes

Soon, you’ll do:

docker run django_app

Instead of:

python manage.py runserver

🧠 Mental Model Update

Today you learned this loop:

docker run β†’ container starts
container stops β†’ container is gone
image stays β†’ reusable

This is the heart of Docker.


πŸ“š Official Docs (Short Reads)

Bookmark them β€” don’t memorize.


πŸ“ Homework for Day 2

  1. Run:

     docker run hello-world
    
  2. Run Python container:

     docker run -it python:3.12
    
  3. Check:

     docker images
     docker ps -a
    
  4. Stop & remove at least one container manually


⚠️ Common Beginner Mistakes

  • Forgetting to remove stopped containers

  • Thinking containers store data permanently

  • Panic when container exits πŸ˜„ (it’s normal)


βœ… End of Day 2 Summary

  • You ran real containers

  • You understand images vs containers practically

  • You learned essential Docker commands

  • You’re ready to build images next


More from this blog

D

devzodiac

12 posts