Getting onboard with Docker
Are you interested in using Docker to change the way you develop and package Linux applications? You’re not alone.
Docker, in a nutshell, is a low-overhead alternative to traditional virtualization. Rather than providing a truly virtualized environment all the way down to the hardware level, it provides a sandboxed environment for your application to run it with only the necessary libraries and operating system components needed to make it run.
From a developer’s perspective, this is great for a few reasons.
First, whatever development you do locally can be a good approximation of the actual live environment where your application will be deployed. Some might remember the “write once, run anywhere” motto once heralded by Java — while “run anywhere” isn’t precisely true, Docker definitely can remove some headaches created by difference in environments.
Second, it means that you can create this custom environment much faster than would be the case with a locally-run virtual machine. A Docker container can often be spun up in seconds, making immediate testing much easier.
Third, Docker creates a software defined environment for your code to run in. Your environment can be version controlled, modified, forked, and rolled back as needed.
Does all of this sound good? Great, let’s get started.
Set up your development environment for Docker
I’ll skip the obligatory installation instructions and getting started tutorial, because there are plenty of good resources for that already. For more on getting started, check out getting started with Docker guide.
As you learn Docker, you’ll undoubtedly spent a good amount of time writing and editing Dockerfiles. Personally, I do pretty much everything in plain old fashioned text editors. At the command line, I’m a VIM fan. If you’re using VIM for your editing needs, be sure to find and install a syntax file for your Dockerfiles to make editing easier. I like this one by Eugene Kalinin, but there are others out there. Similar syntax and autocomplete files are available for other text editors as well, so spend the time to find something that works for you.
What if you use a more full-featured integrated development environment? There are options for you, too. Eclipse has integrated Docker tooling to make development on that platform easier, and it integrates nicely with other tools, for example, if you are doing JBOSS development.
I also find some of the default Docker commands to be a little unwieldy, so I alias some of them to make things easier at the command line. For example, I have this set in my .bashrc file to make container IDs a little easier to find and work with:
alias dl=”docker ps -l -q”
For some other great alias suggestions, check out this list.
Find the right base images to work with
Docker containers are like their own little operating systems — and, in fact, they are!
If you’re using Docker in production, it’s important that you trust the underlying images upon which you base your containers. If you can’t trust each entity who modified your container and verify that chain of trust, you can’t be sure that your container is free from malicious code.
That said, for learning and doing simple development, there are a ton of base images out there to help you get started. Work with Java? Here’s a whole collection of ready-made Java-based images. How about Flask with Python, or Ruby on Rails? You name a stack, and there’s probably already a ready-to-go container out there for you to work with.
But wait a minute. Trace any container back to its original base image, and you’re probably going to find a familiar operating system, whether Fedora or Ubuntu or something else. Make sure the base image you’re selecting has the features and packages you require, and that you’re comfortable configuring it.
Of course, the Docker Hub is one place to find images that fit your needs, but it’s far from the only place.
Find the right learning resources
Docker has a great documentation section, but sooner or later, you’re going to have a question that is easier to figure out elsewhere or you might need a little help with.
The #docker channel on Freenode IRC is a great place to turn for help, but it’s not the only place. Stack Overflow also has a sizable Docker community, and there are a ton of great community-authored tutorials out there.