Understanding what Docker is and how it can help you.

What is Docker?

Great question! Over the last 2 weeks I've had a lot of people ask me, "What is Docker?", "Why would I use Docker?", and "Should I know how to use Docker?".

For this article I'm going to assume you don't know about images, containers, kernels and other operating system intricacies. I'll try to be clear about as much of this as possible — I apologize to those who already know about most of this because this will be review for you.

Docker is a program that lets you run a computer inside of a computer, essentially. To understand the solution we should understand the problem. 

The common problem

If I create a website that uses Node.js and several packages installed via NPM on my Ubuntu 16.04 laptop, and I switch to my Windows 10 laptop — I risk the chance of not having all the right packages installed. Now I know that's what package.json is for, but what if I didn't have Node running on my Windows laptop and I installed the newest version, but was using an older version on my Ubuntu laptop? When NPM goes to download and compile all the packages, it might not compile the same way on both computers. 

Now this is a very simple problem with a simple solution: make sure everyone is using the same version of Node and NPM. But what about managing several projects? Or if you use Node on the front end to code your templates, but you use PHP on the backend? PHP 5.6 is old yet common, and all PHP projects should be using PHP 7 and you've used Composer (or Python with pip) to install a bunch of packages. A lot of servers run Ubuntu 16.04 right now, but if you're not coding your website on Ubuntu 16.04 you risk having your code work differently on one computer. Perhaps PHP's mail() function is disabled by default (AWS disables this by default) but you've built your application to send emails and now all of a sudden it doesn't work. 

This is the common problem of, "It works on my computer.". 

Docker allows your to create miniature operating systems inside your computer that are always to same. If you sent your Dockerfile to a coworker, they could use it to build the exact same operating system and website you've been working on. No more "it works on my computer" problem. No more spending countless hours tracking down why one package or feature works on your computer, but it doesn't work on the server (or vice-versa). Docker unifies all of this so it's never a problem. You can even tell Docker which kind of OS you want to use to build your website: Ubuntu, Red Hat, MacOS, Windows.. almost everything is supported now. 

Why you should use Docker

If you work in a team, this is one of the best ways to make sure everybody is working with the same software and operating system.

If you work alone, you might be thinking, "this isn't useful to me". But Docker has another powerful component: containers. 

You can download a Unix operating system to use inside your Windows or Macbook laptops. And you can install additional software for your Docker setup to use. These are called images, and each image can be used over and over in something called a "container". This term, container, is appropriately named because it contains your code so it doesn't leak into the rest of your computer. 

Let's say your website needs a certain package or software to properly create .pdf files. You could install it on your computer, if you know how. But if you're running a Windows OS, and your coworker is using MacOS, and the server is using Ubuntu, you'll need to install this package or software 3 different ways. Which means you are performing the same task 3 times. That leads to spending more time running into problems, debugging code, and Googling how to install a package on 3 different operating systems. 

Docker eliminates all that pain form your work flow. 

Dependency Containment 

So far all of my examples seem pretty abstract, but I've mentioned these specifically because those are problems I've run into. But here's another one: 

Let's say you're developing a website that uses Python. Your clients server is old, it's using Ubuntu 12 and Python 2.6, meanwhile you have a Windows 10 OS that's running Python 3.6. There are a lot of differences between Python 2 and Python 3. So you go and download Python 2, but it installed Python 2.7 on your computer and you absolutely need Python 2.6 — Python 2.7 just isn't good enough... how do you run Python 2.6, 2.7 and 3.6 on your computer all at once? Docker, who you've just met, is now your best friend. 

You can create a new Docker image that's using Ubuntu 12 and Python 2.6. It won't change anything on your computer, but it enables you to use all of Python 2.6 and Ubuntu 12 in your computer — no partitioning hard drives, no more dependency hell, no more 4 hour frustration-sessions trying to figure out this problem. Meanwhile, outside of your Docker container, you're still using Python 3.6 on your computer, like normal. 

Should you learn Docker?

It's probably a good idea to get familiar with the basics. Learn how to install Docker, learn how to create a new Docker image, turn on (spin up; build) a Docker container and build a basic website inside a Docker container. You don't need to be a Docker expert by any means, but it will help you when you start making more and more websites that are using different technologies. 

Pro Tip

Docker commands (on the command line) can be a nightmare to remember. Take a look at Docker Compose — it'll make your life so much easier with Docker. You can connect containers together, too. For instance, I have a Docker Container just for a Postgres database but I don't have Postgres on my laptop. ;)

Sign up for the newsletter!

Sign up for my free newsletter. No spam, all dev talk and only awesome articles. Opt out at any time, no hard feelings.





About the author

Kalob Taulien

Full stack developer. Entrepreneur and dev teacher. Over 100,00 students world wide.

I started making websites long before CSS had rounded corners, before JavaScript was more popular than oxygen and videos could only be played through Macromedia Flash. 

Today I'm a full stack LAMPP (PHP and Python) developer that enjoys teaching web development and working with startups. 

Connect with me: