DEV Community

Lawrence
Lawrence

Posted on

Docker: The Tool That Ended "It Works on My Machine"

Every developer has said it at least once: "But it works on my machine." Maybe your laptop had a slightly different version of Python, or a library installed months ago that you forgot about, or a database configured just so. The code was fine. The environment was the problem, and nobody could tell you exactly how the two differed. Docker is the tool that made me stop having that conversation, and it's one of the few pieces of technology I'd call a genuine turning point in how software gets built and shipped.
So what is Docker? At its simplest, it's a way of packaging an application together with everything it needs to run: the code, the runtime, the libraries, the system tools, the settings. That package is called an image, and when you run an image, you get a container. A container is an isolated little world where your app runs, and it behaves the same on your laptop, on your colleague's laptop, on a test server and in production. You build it once and run it anywhere Docker is installed.
People often compare containers to virtual machines, and the comparison is useful up to a point. A virtual machine carries an entire operating system inside it, which makes it heavy, slow to start and hungry for memory. A container shares the host's kernel and only packages what the app itself needs, so it's much lighter. Containers start in a second or two instead of a minute, and you can run dozens on a laptop without it complaining. The isolation isn't as strict as a full VM, but for most day-to-day work that trade is more than worth it.
The background is a nice story. The ideas behind containers were around long before Docker. Linux had been growing features like namespaces and control groups for years, which let you wall off processes from each other, and earlier projects had built on them. But using those features directly was fiddly and the preserve of experts. Docker came out of a company called dotCloud, and it was shown to the public in 2013, built by a team that included Solomon Hykes. What they did wasn't invent containers so much as make them pleasant. They gave people a simple command line, a clean way to describe an image in a text file, and a place to share images, and suddenly everyone could use something that had previously been for a few specialists. It spread incredibly fast, and today the container format has been standardised by the wider industry, so Docker is no longer the only tool that can run these images.
The heart of the everyday experience is the Dockerfile, a short text file that describes how to build your image. You say what to start from, copy in your code, install your dependencies and say what command to run. That's it. Because the file is just text, it lives in Git next to your code, and anyone can read it to understand exactly how the app is put together. I love that. The setup instructions that used to live in someone's head, or in an out-of-date wiki page, become something that runs. Images are built in layers too, so Docker can reuse the parts that haven't changed, which keeps rebuilds quick once you've got the hang of ordering your steps sensibly.
Why do I think it's great? For me it comes down to a few things. The first is onboarding. A new teammate used to spend a day or two fighting with installation instructions, and now they run a command or two and the whole project is up. The second is consistency, which is the "works on my machine" problem finally put to bed, because the machine is shipped along with the code. The third is how well it plays with others. With Docker Compose, you can describe your app, a database, a cache and a queue in one file and start the lot with a single command, which makes local development feel almost unfairly easy. And the fourth is that it became the foundation for a lot of modern infrastructure. Tools like Kubernetes exist to run and manage huge numbers of containers, and learning Docker is the natural first step into that whole world.
It's not perfect, of course, and it would be dishonest to pretend otherwise. Images can balloon in size if you're careless. Containers are disposable by design, so anything you want to keep, like database files, needs to live on a volume or you'll lose it when the container goes away. Security needs real thought, because running everything as root or pulling random images from the internet is a bad habit. And Docker has a learning curve of its own: networking and volumes confuse almost everyone at first. There are alternatives too, like Podman, that some people prefer for various reasons. None of this changes my view, though. The problems it causes are far smaller than the ones it solves.
If you've never tried it, the best way in is small. Install Docker, run a ready-made image like a database or a web server, and watch it appear in seconds with nothing left cluttering up your machine afterwards. Then write a Dockerfile for a tiny project of your own. Somewhere around that moment, I think, you'll feel the same thing I did, which is the quiet relief of knowing that what you built is going to run the same way everywhere.

Top comments (0)