Dockerize — Learning Docker Series 1

Covenant Chukwudi
MyCloudSeries
Published in
4 min readFeb 6, 2019
dockerize — My Cloud Series

Dockerize

[Verb]

  1. To containerize an app using docker
  2. To be awesome.

Docker is a breakthrough in improved software delivery. Docker is a tool that enables you to create, deploy and run applications using the concept of containers.

This is a part 1 of our Dockerize series in learning Docker. No per-requisite knowledge is needed.

By the end of this series, you would be able to conveniently use Docker, create images, extend images and do a whole lot of other awesome things at scale😎.

Installing Docker

Let’s install docker on our systems. This tutorial is wholly based on Linux containers. Docker has separate distributions but we’re entirely focus with the SE version which is completely free.

At least a computer system with 4gb of RAM is required to comfortably run docker.

Windows

To install docker on windows 10 pro/enterprise, simply follow these steps:

  1. Download docker for desktop from here.
  2. Run the installer and follow the instructions there.
  3. Adjust the memory and space limit based on your convinience (associating a ram of at least 2gb is recommended)

If you use windows 7/8/8.1, It is much more advisable to just upgrade to windows 10 but if you can’t, you would have to use a lesser featured tool called Docker Toolbox.

  1. Download docker toolbox from here.
  2. Run the installer and follow the instructions there.

Mac Os X

You have to be running a minimum of Os Yeosemite (10.10.3) to be able to use Docker for mac

  1. Download docker for mac from here.
  2. Run the installer and follow the instructions.

If you are using any version lower than Yeosemite like Snow Leopard, you can download the lesser featured Docker toolbox.

Linux (Debian variations e.g Ubuntu)

Docker supports linux very natively, you can follow the steps in this documentation if you are using a debian or a variant of debian like Ubuntu.

Containers & Images

An image is the compact representation of binaries, libraries, packages and source code that make up your application. A container is an instance of an image running as a process.

“You can have multiple containers running off the same image”

Take for example, you have a nodejs-express app that runs on ubuntu 16.04, Docker allows you to describe and publish the entire environment, libraries and modules together with your nodejs app as an image. The image becomes a blueprint from which “instances”(containers) can be created to actually run your app.

Let’s delve deeper into Containers

The Docker hub: hub.docker.com has a wealth of predefined images that we can either use in it’s entirety or extend for our specific usecase.

We are going to work with the image of a popular web server called tomcat. Open your terminal if you’re on Linux/Mac or Powershell if you’re on Windows 10 and run the following command.

docker container run --publish 80:8080 tomcat

then open your browser and type “localhost”, you should see the default apache tomcat page opened.

What the above command simply did is to instruct docker to look for the latest version of an image called “tomcat” and create a running instance of that image.

It starts first by searching your local cache first to see if it can find the image, if the docker-engine doesn’t find it, it heads over to hub.docker.com and pulls the tomcat image.

The “ — publish” option makes the port 8080 inside the container to be accessible through port 80 on the host machine, what this means is that docker would route all requests on our host system from port 80 to port 8080 inside the running container.

Since Tomcat by default starts up on port 8080, we are able to access the tomcat server on our system when we type “localhost” in a browser.

You would notice that the process runs in the foreground thereby preventing us from doing any other thing on that terminal, to enable your docker container run in the background, simply use the “ — detach” attribute.

docker container run --detach --publish 80:8080 tomcat

The above command would enable you create a container from the “tomcat image” and run in background.

To see a list of containers that are currently running, simply do:

docker container ls

To stop a container that is running, simply do:

docker container stop <containerId>

The container id is usually a long hexadecimal code string.

To view the logs of a running container, simply do:

docker container logs -f <containerId>

Docker has a concept called “named containers”, which allows you to specify names for the containers you create instead of allowing docker use a random-default. To create a named container simply use the “ — name” attribute, e.g:

docker container run --name CovenantServer --detach --publish 80:8080 tomcat

To see the logs of a named container, simply do:

docker container logs <containerName> #in our case CovenantServer

To have an insight and see the list of processes running in a container, simply do:

docker container top CovenantServer

To delete a container, simply type:

docker container rm -f <containerName>

To view a list of all other awesome things you can do with containers, simply type:

docker container --help

Sticky Notes

  1. Docker is a tool that enables you to create, deploy and run applications using the concept of containers
  2. An image is the compact representation of binaries, libraries, packages and source code that make up your application
  3. A container is an instance of an image running as a process on a host machine.
  4. We can have multiple containers of the same image.
  5. To create a container from an image, we simply use the command “docker container run”.

Conclusion

Docker is a really awesome tool that has revolutionized the way we build software.

Watch out for subsequent publications of our series where we go deeper into containers, networks, images and all the goodness of docker.

Hire me

Have an interesting project?, great!!. Shoot me an email covenantchukwudi@gmail.com

--

--

Covenant Chukwudi
MyCloudSeries

I build products that would have positive effect on lives