Let's Talk About Docker
- Programming
- Database
- Hosting
- Technology
- System Administration
- Software
- Small Business Tools
- Web Design
Recently I was in several conversations with my coworkers about Docker. Some were filled with concerns, others had stars in their eyes, and others had ideas that were just completely wrong. I thought it would be good to discuss these confusions and concerns, and clarify exactly what is going on with this software.
Group #1: Docker is Completely New and Scary
New things are scary. We get that. Docker is especially frightening, as it flips traditional workflows on their head.
Over the last ten years, when it comes to application deployments, not a lot has changed. We may change the hardware on which they run, and even to the point of virtualization. But everything has basically been done through the command-line, and moreover done manually.
Developers and system administrators would argue that Docker is the new kid on the block, it's probably not trustworthy, and will take a very long time to get working.
People in this group are also averse to the time commitment required to learn the new approach to deployment. One developer I spoke with recently compared learning Docker to making the switch from one trusted, stable language to another bleeding-edge, untested language. The proposition seems very risky.
Group #2: Docker Solves Every Problem Ever
Some people get the idea that this software is going to completely revolutionize how absolutely every other piece of software is written, making everything previous to it obsolete.
While it is clear that Docker does change how things are accomplished, it is not a solution to the world's every problem.
When asked how Docker will improve things, Docker fan boys and girls will often say its just like what you know and love, but better in every way.
From Packages to Package Management
Neither of these viewpoints are correct.
It is difficult to come up with an appropriate analogy for what is actually going on with Docker, and how it relates to what we do. The simplest analogy I can come up with is going from manually installing packages to using a package management system.
Let’s talk about what it really does at a basic level. There are many ways to do may things I talk about here, but I am just going to talk very simply.
It is a Fancy, Scripted, VirtualBox
Let's start from a point that everybody understand: VirtualBox (if you don’t know what that is, think of it as your computer running a bunch of other computers boxes inside of itself, virtually). There are not too many people that would argue that VirtualBox, or virtualization technologies like VirtualBox, are at all scary. Most would actually argue that virtualization is awesome. They are cost-effective, highly reliable, very secure, and are generally the best way of making the most use of computers.
So how is Docker different from VirtualBox?
- The first major difference is that Docker allows you to easily create shared folders with the virtual machine, and a host machine.
- Docker allows you to save massive amount of resources by sharing much of the overhead (RAM, HDD, CPU) of the operating systems between all of virtual machines running. So instead of having your time service running eight times because you have eight virtual machines running, it runs just once.
- There is a massive repository of pre-made images for various software and services already out there, developed by the people that wrote the software; which means that every piece of software you have running is running in the exact environment the developers intended (more on this later).
- Creating new machines is done in one line on the command-line. These can also be scripted very nicely into a single file that will create all of your images in one simple command:
docker-compose up
Beyond these details, there really is not much of a difference between Docker and every other virtualization platform out there. It is just a virtual machine, with some nice features. Don’t get too freaked out, and don’t get too excited. It’s just a virtual machine. Everyone uses them, almost every website on the internet (and intranets) today are hosted on one. The only difference: now we have more power.
It is Just a Virtual Machine
Okay, so we established that there really isn’t anything that crazy going on here. It’s just virtualization software, and it runs glorified virtual machines. So let’s talk about why people are so excited about it. It is a virtualization platform…
…With tons of pre-made images
One really nice thing about Docker is that it’s really popular. Just about everyone that is writing software nowadays is creating a Docker image for it. Why bother? Well if you’ve ever written software for the web, you’ll know that every browser out there handles every single line of code a little bit differently. Whether that is HTML, JavaScript, or CSS, every browser is ever-so-slightly different, and every browser has its own exceptions and nuances.
That is the way it is with operating systems and software. Every single operating system handles things just a little bit differently, even more so than browsers. The magical part of a Docker is that it allows every single piece of software to run on the ideal operating system for itself, including all of the subsequent packages and libraries that it needs and the state that every piece of software needs.
Imagine we have a factory with a long production line and a hundred employees being forced to listen to the same music, eat the same food, and work in the same work boots. Their efficiency would be significantly diminished because they don't have their own ideal work conditions. With Docker, we are giving each of those "employees" their own music, their own food and their own work boots, so that they will work to their best potential.
Let’s take a LAMP stack: you can have Apache running on CentOS, PHP running on Ubuntu, and MySQL running on Debian, all on the same server, sharing resources, talking to each other, and running very efficiently.
This means that you can stop messing around with figuring out what other requirements are, figuring out where libraries and configuration files are, and wasting time. In addition, once you have Docker configured locally, you never have to go back and redo your work in a development environment, production environment, or in your coworkers environment. They are all running in the same exact image as you.
…With great support for Version Control
We start off with a command that I think all of us will be able to handle:
git pull
docker-compose up -d
Because of the way that docker handles it’s filesystem, it allows you to keep all of the really important files in one place. Let’s take a peek at what that looks like in a LAMP stack:
/ # Git Project Root (let's say it's in /home/ec2-user/myLamp)
/.git
/web # Where all your public web files would go
/localFiles # This folder is GIT Ignored
/localFiles/mysql # The MySQL data files are stored right here
/.gitignore
/php.conf
/httpd.conf
/my.cnf
/docker-compose.yml
Let’s talk about a few cases here:
- Developing With Docker: With this setup, you would just run
docker-compose up
and you are off to the races. Any code changes are immediately reflected because the code is served straight from your local machines directory (it isn’t actually in the VM) - Getting a Friend Spun Up: Once they install Docker (which is available for pretty much every operating system in existence), you have them run:
git clone http://github.com/my/repo.git; docker-compose up
. They are immediately ready to rock and roll with your project, so you can explain more time explaining what in the world you were thinking when you wrote [insert your embarrassing code example here]… - I Need to Show My Client: Just to find yourself a server that you want to post your application to, install docker (with
yum install docker; chkconfig docker on
) and rungit clone http://github.com/my/repo.git; docker-compose up -d
. - Time to Go Live: find yourself another server, or another port on that server, or another IP on that server and
git clone http://github.com/my/repo.git; docker-compose up -d
- My Computer Died!: Because you are using version control and committing often (right?) you can get up and rolling on your mom's computer after installing Docker with:
git clone http://github.com/my/repo.git; docker-compose up
(are you starting to see a pattern here?) - I Need 1000 Instances of My App Running!: Congratulations! Run
docker-compose scale myapp=1000
and you now have 1000 instances running. - I Need Backups of My Data: No problem, because all of your important data is in one place, you don’t have to back up all of the unnecessary library and application files. Your software is backed up already in your version control system, and if you’re using git, on every single computer that has it cloned. All you need to back up is your actual database data, what you don’t have to go searching throughout your filesystem to find, it is conveniently placed right inside your project directory (
/localFiles/mysql
). This makes backups much smaller, faster, and way easier. This could even be done with a separate version git repo. - I Need to Restore My Data!: Remember that get clone command above? Yeah, run that, restore your backup data base data where you found it (and since the backup is so small it shouldn’t take long).
docker-compose up -d
and you are back in action.
…That is Easily Reusable
Does a client who wants a site just like that other site you built? Do you have a yet another client who wants yet another of the same type of site? Are you tired of trying to remember all of the bash commands and little nuances to getting that software running on another server? Or setting it up in your IDE?
How do I do this with Docker?
git clone http://github.com/my/repo.git
cd myRepo
git remove remote origin
# Create a new Git REPO
git remote add origin http://github.com/my/repo-copy.git
git push -u origin master
docker-compose up -d
What did I do there? I just copied repository, and ran my nice Docker compose line. You now have the exact same environment and can deploy it anywhere you want without ever having to install any packages, mess with configurations, or debug some strange version discrepancy.
…With Support from Big Hosting Players
Because docker has become so popular, big names like Amazon AWS, and even open source providers like OpenStack have made it even easier to deploy your software straight to the cloud. You don’t even have to create a new machine.
As support and adoption grows for Docker and applications like Docker, it will become easier, and will allow developers to be developers, and leave the system administration work to the system admins.
From Manual Packages to Package Management
Do you remember the day when you first discovered package management? When it clicked in your head; the possibilities? Do you remember your frustration when you were stuck because of some stupid mistake? When you realized you shouldn’t edit libraries directly? How about how pretty your version controlled code looked like when you pushed it? Or what it was like to give it to your coworker?
This is very close to the way Docker is. There are some hurdles. It does require that you do things differently. However, I don’t think many people would argue against the virtues of using a package management system. Docker isn't perfect and has its own issues, but over the long haul, it can save significant time. It forces us to code properly, something every software product always benefits from. It makes updates, transfers, etc. 1 billion times easier, along with all of the other features and benefits that go along with it.
Don't Panic
Remember, this is just a virtual machine. This is not a new programming language. This is not really even a new way of running software. It’s still just a virtual machine. The only difference is that it’s a lot faster and a lot easier to get started.
There will be a learning curve, you will have stupid issues that you didn’t know existed, you will likely crash at some point, and be extremely frustrated. However if you are looking to escape this, then I recommend you get out of technology entirely, and you may perhaps need to leave the planet. Learning, mistakes, and hard lessons are unavoidable. That’s life.
You can continue in the old way of doing things, or you can accept the fact that you’re going to make mistakes and experience hard lessons, and learn something new and perhaps make your life just a little easier.
Docker is cool. Don’t panic, and don’t get too excited.
Life will go on!