Get Dockerized – Docker Overview In 5 Minutes

What is Docker?

Docker is a virtualization environment; the concept is identical to that of  virtual machine, but significantly more lightweight.  You could construct a virtual machine image to run a single service (e.g. a web server), but launching an entire VM for a single service may be overkill.  Instead, that web server (and required resources) can be packaged into a docker image which can be launched as if it is a single lightweight process.   Where you could probably only run a single Virtual Machine instance, you could run dozens of docker images.

So, it’s essentially a virtual machine?

Yes.  But significantly more lightweight.  Typically, a docker image is designed to run a single process (e.g. web server). You could then create a second docker image to run another process (e.g. a database instance) and then a single host could run both docker images.  Each one, however, is a “proper” instance of an OS.  You could open a bash shell to the running docker and issue commands if necessary.

What exactly is a docker image?

A docker image is a snapshot of the components that make up the docker’s purpose.  For example, a docker image for a web server would probably contain just the basic core elements of the operating system (e.g. RedHat) and a basic install of the web server software – all configured for runtime.  So someone who wants to use that web server could just download that docker image and “run” it.

What is a docker container?

A docker container is a running instance of a docker image.  It’s a subtle but important distinction.  You download (or build) a docker image.  It runs in a docker container.  Think of the image as the files that make up the instance; the container is the running instance.

How to see all docker images on my machine?

You can see the contents of your local repository by running

 Okay, now that I have the image, how do I run it?

You can use the docker run command.  This will launch the docker image into a container.

There are many options to the docker run command, but a basic run would be like this:

How do I know my docker container is running?

Use docker ps command.

Can I poke around the inside of the running docker image?

Yes you can!  Using the docker exec command, you can actually access the bash shell.

-ti  – run in “interactive mode” with a TTY.  If you don’t provide this, bash will execute and immediately exit.

This will launch an instance of “bash” on the docker container.  You should be shown the actual bash prompt. Notice that you are at the file system/environment of the docker container.  You can run standard commands like ls and ps which is handy for troubleshooting!

Interestingly, your docker container may be an entirely different version of the OS than your host! When you are done, you can just type exit

How can I find out the IP address of a docker container?

The easiest way is to use docker exec (as described above) and pass in the ifconfig command.    (Note that the “-ti” parameters are not required as this is a one-off command execution)

How do I build my own docker image?

A thorough discussion of this is outside the scope of this document, but the basic idea is that you create a Dockerfile and then run the docker build command on it.

A Dockerfile is essentially a script of how docker should construct the image.  It often starts with a FROM statement – which specifies a docker image to use as a base followed by additional customization steps such as the installation of additional software or the copying of files into the image.

Yes, this means that you can build a docker image on top of a docker image, which is handy for promoting re-use between projects.

How do I kill a running docker container?

How do I delete a docker image from my local repository?

Make sure you’ve killed the docker image first.  Then:

How do I kill ALL running docker containers?

How do I remove ALL docker images?

If it took you more than 5 minutes to go through this article, just let me know ;)

Leave a Reply

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