DEV Community


Posted on

What the heck is Docker used for

If you recently had to deal with setting up a dev environment or try deploy to
production, then chances are you have encountered docker either via search or as
a suggested solution.

What is Docker anyways?

One of the most difficult thing for me was figuring out what Docker was exactly
for. Because for every material I found that explained what its for, used it in
a different way than the previous I read even the official docs. So I am going
to give you a layman's definition. Docker is a piece of software that makes it
possible to have a copy of an operating system(OS) run in isolation on your
machine.Period (“Devs start ranting!!”).Wait! isn’t this like a virtual machine
or what something like vagrant does? Yes its the same thing but the interesting
part is how it does it.

How Docker works?

So if you want to run a copy of an OS on your host machine your best bet is to
setup a virtual machine, dual boot or use a tool like vagrant with the latter
making the virtualisation process automated and sharable . Docker does the same
thing but doesn’t need another OS installed, instead it uses the host OS. ie:
the operating system your computer is running by isolating parts of the host
resources to create a virtual machine. Some of the things Docker isolates
includes network, space and processes. Since Docker makes use of the host OS it
means there is no OS setup and boot up process . This makes spinning up a
virtual box quicker. Ok so we can’t keep calling the box Docker sets up for
you a **virtual box or machine. **Instead we refer to them as images. We will
touch on this a little bit more soon.

How do I get started?

Oh almost escaped me, the technology (LXC) that Docker uses to provide the
isolated environment is only available on linux. You can read more on this from
Wikipedia. And so setting up docker varies
depending on your OS.

Its actually easier on OS X and Windows. Just follow
here for OS X and
there for Window. The only linux
distro I have run Docker on is Ubuntu. Well since the technology Docker runs on
is native to the linux kernel it should be straight forward to install right ?
It wasn’t when I started :(. But I found an easier way to do this by using the
binaries. **NB: **This might not be the recommended way to install Docker but
its there in the docs and it works so ……………………… To get started with installing
Docker using the binaries go
and follow the instructions to set it up. You can check if the installation was
successful from your terminal by typing out “docker -v to display the version
of Docker you have installed.

Really what exactly can I use Docker for ?

Well as I stated earlier Docker works just like a virtual machine. Like the one
you set up for Ubuntu on your windows box only difference is you don’t have
access to the OS GUI just its terminal like vagrant has (if you have used it
before you know what I mean). Some of the common uses of Docker includes setting
up** dev environments , production setups, distributing software etc.**

There you have it “uses of Docker Boom!!!!

But how ?

Well writing about how Docker is actually used for the above will require a
complete blog post. The rest of the post will be about how Docker makes software
distribution easy.

Imagine you found an interesting open source software on the web and wanted to
try it out , but then it requires you install a whole bunch of stuff. Docker can
free you from this.


Ghost is an open source blogging engine that has gained popularity. But to
run this it requires that you install node and a ton of other stuff, maybe am
exaggerating :). To do this the Docker way we simply run

$ docker pull ghost
Enter fullscreen mode Exit fullscreen mode

This pulls the ghost setup onto your machine. This is known as an IMAGE.
This might take sometime to complete depending on your internet speed.

Once this is done you should be able to view the list of images you have with

$ docker images 
Enter fullscreen mode Exit fullscreen mode

Now the next step is to spin a container from the image we just pulled.The
concept of containers and images usually confuses most people. Images are
kinda like OS ISOs and Containers like turning on a PC. This is not exact
but will suffice for now. So lets go ahead and spin a container from our image.
Shall we?

This will spin up a container running on port 8080. You should be able to access
ghost on http://localhost:8080/

Ok lets take a look at that last command

docker run 
Enter fullscreen mode Exit fullscreen mode

This is the command for spinning a container from an **image . **The next
important part of that command is

Enter fullscreen mode Exit fullscreen mode

This simply maps the port number 8080 of your machine to the port 2368 within
the container. Its why we accessed ghost using

You can also list out all running containers with

docker ps 
Enter fullscreen mode Exit fullscreen mode

All this without having to go through the hassle of installing much. This makes
Docker an excellent way to distribute software. So just imagine having to deploy
ghost on a production server, Docker makes this a breeze

Last words?

You can find docker images of popular softwares from the Docker

A few commands to get familiar with includes and not limited to

$ docker exec -i -t <container_id> /bin/bash
Enter fullscreen mode Exit fullscreen mode

This provides you terminal access to the container. You can find the container
id using

$ docker ps 

$ docker stop <container_id> 
Enter fullscreen mode Exit fullscreen mode

The above command stops a running container. Once a container is stopped the “
docker ps command wont list it out so you will need to add the “-a flag to
list stopped containers as well

And to start a stopped container

$ docker start <container_id> 
Enter fullscreen mode Exit fullscreen mode

There are a shit ton of other stuff Docker provides that makes it powerful
compared to something like vagrant. For example Docker allows you to commit a
Container to an Image, this means you can save the state of a running
Container(software) and share it with others.

Well if the terminal is not your kinda thing , don’t worry there are visual
tools out there that make working with Docker much more pleasant. My personal
favourite is Portainer .

There is soo much Docker offers. We have barely began to scratched the surface.

How do I learn more ?

Docker provides an excellent documentation, only
thing is its best for getting more detailed stuff . I will advice going over
other materials if you are just getting started and use the
docs for detailed references.

Here are a few materials you can get started with :

So now what ?

I don’t know love the post, comment and leave…

Top comments (0)