DEV Community

Cover image for Docker for Broke Developers: Learning It the Hard Way
N4xt0n Tux
N4xt0n Tux

Posted on

Docker for Broke Developers: Learning It the Hard Way

=====================================================

This is my journey of learning Docker. I'm figuring it out as I go. I'll share what I've learned so far.

The Problem


I've been avoiding Docker for a time. It seemed complicated. I thought, "Why do I need containers when I can just run my code on my machine?". Then I tried deploying my app and it was a nightmare. The "works on my machine" problem drove me crazy. I installed Python 3.11. My colleague had 3.9 and our dependencies broke. I spent hours debugging environment issues of shipping my app.

What is Docker?


Docker is a way to package my app and all its dependencies into a container. I can ship this container anywhere. It will run the same. No more environment issues.

  • I used to have to install the Python version, pip packages and system libraries on my machine and server.

  • . With Docker I can build an image that defines everything my app needs.

  • I can run this image on my laptop, server or CI/CD pipeline. It will always be the same.

My First Docker Fail


I downloaded Docker Desktop. Stared at it unsure what to do. Most tutorials start with a Dockerfile. I didn't understand what it was doing.

  • FROM: Start with a base image (Python 3.11).

  • COPY: Copy my code into the container.

  • WORKDIR: Set the working directory inside the container.

  • RUN: Execute a command inside the container.

  • CMD: Run a command when the container starts.

The Moment It Clicked


I built my image and ran it. It worked! The same way on my laptop my friends Mac and a Linux server. I realized it's not magic; it's reproducibility.

What I'm Still Figuring Out


  • Docker Compose: Running containers together (e.g. Python API, PostgreSQL database, Redis cache).

  • Image size: Making my images smaller (e.g. using a base image removing unnecessary dependencies).

What Docker Has Saved Me


  • Environment consistency: My app runs the same on any machine.

  • Onboarding: New developers can just run docker-compose up to get started.

  • Deployment: I can push my image to a registry. Deploy it to a server without worrying about environment issues.

The Things That Still Confuse Me


  • Volumes: Persisting data between container restarts.

  • Networks: Advanced container-to-container communication.

  • Multi-stage builds: Optimizing my Dockerfiles.

What I'd Tell Past-Me


  • Docker isn't magic. It's a way to package my app and its dependencies.

  • Start with a Dockerfile and get it working locally.

  • Don't worry about optimization at first; just focus on getting it working.

Next Steps for Me


  • Build a multi-service app with Docker Compose.

  • Push images to Docker Hub.

  • Deploy to a server using Docker.

Have you struggled with Docker? Share your pain points. I'm learning in public. Your experience might be the next article.

Resources That Helped Me


  • Docker official "Get guide.

  • Docker Compose docs.

  • YouTube: TechWorld, with Nana (Docker series).

  • Play with Docker ( online practice).

Top comments (0)