So you want to start kicking the tires of Docker, but you don't want to have to go all the way with the installation of the necessary software. Or maybe you want to have the ability to quickly spin up a virtual machine that contains everything you need to practice with Docker. For that, you want to use boot2docker.
This is a lightweight Linux distribution, based on Tiny Core Linux, that contains everything you need to start working with Docker. It runs completely from RAM, has an incredibly small footprint (~27MB), and boots in about five seconds. And for those unfamiliar with Linux, you won't have to bother with installing the platform.
I'm going to show you how to spin boot2docker up in a VirtualBox Virtual Machine in about two minutes (depending on how fast your network connection is). We'll then test it by running the tried and true NGINX as a container.
Let's get started (don't blink, you might miss something).
Creating the virtual machine
The first thing you must do is download the .iso image of boot2docker. Once you have that downloaded, create a new VirtualBox virtual machine using this image. There is nothing special about the virtual machine, other than making sure you set the Networking to bridged (Figure A - in case you'll be spinning up containers that need to be reached on your local network).
Running the VM
Once you have the VM configured, start it up. The boot process will fly by very quickly and land you on the boot2docker bash prompt (Figure B).
At this point, there is no installation to deal with; boot2docker is ready for you to start working with Docker. Yeah, believe it or not, that's all there is to it.
Deploying that container
From the boot2docker command prompt, issue the following command:
docker run --name docker-nginx -p 80:80 -d nginx
The above command will pull down the NGINX image from the Docker Hub and then run the container, based on that image, in detached mode. You can now point a browser to http://SERVER_IP (Where SERVER_IP is the actual IP address of the boot2docker virtual machine) to see that NGINX is, in fact, running.
If you're not sure what the IP address of your VM is, issue the command ifconfig to find out.
All in about two minutes.
Of course, you can do much more than just deploy the NGINX container. In fact, with boot2docker, you can do pretty much anything a regular docker server could do (even create a Docker swarm). Just remember, if you shut down boot2docker (or reboot it), you will lose all your work. For that reason, boot2docker is best thought of as a testing ground and not much more. Of course, should you want to save your work, you can always save the virtual machine state (so the next time you fire up the VM, you'll be exactly where you left off).
No faster way to test Docker
If you're looking for an amazingly quick way to test Docker, learn the ins and outs of Docker, or test your current skill set, you won't find a faster, easier method than by using boot2docker. If you don't like the transient nature of boot2docker, your next best bet is to simply create a full-blown Docker server using VirtualBox (or VMWare) and then clone it as needed. However, that's more work and you won't find a full-blown server to boot as quickly and be as easily rolled back to zero than with boot2docker.
- How to connect Docker data to its host filesystem (TechRepublic)
- How to create a Docker swarm (TechRepublic)
- How to get Docker Shipyard up and running with a single command (TechRepublic)
- An introduction to the Linux home directory (TechRepublic Video)
- Docker LinuxKit: Secure Linux containers for Windows, macOS, and clouds (ZDNet)
Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.