Docker basics in a nutshell

I have a number of posts from my playing around with Docker so far. I’ve seen a number of posts from people asking how they should get started with Docker. There’s a number of getting started guides that will get you up and running. Try the Getting Started tutorials on the Docker site.

I’m not going to attempt to re-write my own version of other tutorials as they are good already. Instead, I’m going to distill down a few core steps as a quick reference and a quick example. If you’ve no idea what Containerization is about, this page is a good overview.

Assuming first if you’re on Mac or Windows you’ve already installed the Docker Toolbox. If not, head over here and follow the instructions.

In a nutshell:

  • images are read-only definitions used to create a container (they describe the content of a container, starting with a base image, at the very least a base Linux OS)
  • You can browse shared images at Docker Hub (or host your own hub)
  • images can be used as the starting point and extended to create other images
  • a container is an instance of an image that can start, pause, stop

Start the Quickstart Terminal.

Let’s pull an image (busybox) and start it up:

  • docker pull busybox

Now let’s run a container based on this image, run it interactively (-i) capturing the tty (-t) and execute a shell (the hex value is the id of the image):

  • docker run -it c51f86c28340 sh

On a reasonably recent machine you’ll probably see the sh prompt appear in a second or less. If you exit the shell, your container will also terminate because it’s not running anything (by exiting the shell you terminated the command you asked the container to run).

You can see currently running containers with ‘docker ps’ and list all containers included recently terminated with ‘docker ps -a’:

Let’s start it up the same container again in interactive mode: ‘docker start -i 9fd9f0402821′ :

Each time we start it up, you should notice it starts pretty quick, in 1 second or less.

Containerization vs Virtualization

If you’ve ever installed a guest OS in a virtual machine using virtualization software like VirtualBox, VMWare or Parallels, you should now be noticing a major difference between containerization and virtualization. How did that container boot so fast??!!

The difference between these two approaches is that virtualization allows sharing of the platform hardware, so multiple guest OSes can be installed on the same hardware. Containers on the other hand allow sharing of the operating system – each container shares common libraries and resources from the underlying Linux OS. Containerization solutions like Docker rely on features natively provided by Linux to achieve this. Running Docker on a non-Linux platform, like Windows or OS X requires hybrid approach running a Linux guest in a Virtual Machine – the Docker Toolbox and docker-machine takes care of this for you.

Next steps from this point would be to create your own image running some service or app in a container. If you look through some of my previous posts, hopefully these will now make more sense now we’ve covered some of the basics.

Go try it out for yourself!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.