View Categories

Docker: What It Is and How to Install It

A dock stretching out into open water.
  • Jun 09, 2020
  • 0
  • by A2 Dev Team

Developers typically build and run web applications through the use of virtual machines and hypervisors that rest on top of a host’s Operating System (OS). However, this method comes with some downsides that can affect your program’s speed, portability, and scalability.

That’s where Docker comes in handy. This tool uses containers to improve your web apps’ performance. It also enables you to package programs so they can run on multiple machines with different configurations.

In this article, we’ll provide an overview of what Docker is. Then we’ll talk about why you might want to use it for your development projects, and walk you through its installation process. Let’s get to it!

An Introduction to Docker

Docker is an open-source productivity tool. It’s a platform that helps developers prepare their applications for delivery:

The Docker homepage.

Docker does this through the use of ‘containers’. These are units of software that include your app’s code and all of its dependencies. They isolate software from its environment, so that it runs uniformly regardless of the OS it’s deployed on.

To put it another way, Docker helps developers by streamlining the process of delivering software to operations (ops) teams in a standardized format. It makes shipping code to servers easier.

3 Key Advantages of Using Docker

Using containers to create and deploy web apps may not seem vital at first glance. However, there are many ways Docker can help to improve your workflow as a developer. Here are three of the primary benefits.

1. It Provides Increased Scalability

Being able to scale your applications based on demand instead of relying on a singular point of failure helps you provide end users with a more reliable program. Docker’s swarm mode enables you to do this and more.

A ‘swarm’ is simply a cluster of Docker engines that work together to deploy your application. You can use this feature without the need for any extra software – it’s available on every Docker installation.

This feature provides a host of benefits, but some highlights include:

  • Seamless scalability. Simply define the number of tasks you wish to run, and Docker will add or remove tasks as necessary to maintain your desired state.
  • Desired state reconciliation. Docker can recognize discrepancies between your desired state and the actual state of your application. It will automatically adjust to resolve those issues.
  • Load balancing. You can connect to an external load balancer, or use swarm mode’s native features to distribute containers between nodes.

Ideally, your web app will continue to grow over time. Being able to easily scale up to meet the needs of your users could save you a lot of trouble down the line.

Likewise, scaling down can improve your app’s performance in certain situations. This will enable you to provide a better overall User Experience (UX), while also making sure valuable server resources don’t go to waste.

2. Docker Improves Application Performance

There are other ways Docker can help to improve your application’s performance. In fact, the container system it’s built on is especially well-suited to that task.

Containers enable you to ship your application with only the elements that are not already running on the host computer. This enables you to reduce the overall size of your program, and therefore speed up performance.

A virtual machine, on the other hand, must include a virtual OS, all the libraries and dependencies needed for your app to run, and your code. Not surprisingly, all of that can take up quite a bit of space on a server.

In some cases, you may be able to achieve even better performance by using containers and virtual machines together.

3. Containers Streamline Portability Between Servers

Docker’s most significant benefit is that it enables developers to more easily deploy their applications. Containers make portability between servers much simpler.

If you’ve ever found yourself in a situation where your program works flawlessly in your development environment, but fails to do so when deployed in a live environment, you know the value of this feature. With containers, testing becomes more accurate and reliable.

By creating much more flexible end products that can be used across multiple platforms, you’ll increase your pool of potential end users. Ultimately, this may help you build more ‘sellable’ programs.

How to Install Docker

At A2 Hosting, we support Docker usage on our unmanaged Flex Dedicated Server plans. You can install Docker on CentOS 6, CentOS 7, and Ubuntu servers.

First, log in to your server using Secure Shell protocol (SSH). As the root user, upgrade the system. CentOS users should type in the following command:

yum -y update
reboot

Then, log back in to your server using SSH and add the Extra Packages for Enterprise Linux (EPEL) repository, using this command:

yum -y install epel-release

Verify that it has been properly added by entering:

yum repolist

This should return your repository list output. Look for the following line:

epel Extra Packages for Enterprise Linux 6 - x86_64

If it’s there, you can proceed with installing Docker. Run this command:

yum -y install docker-io

Then, start the service by entering:

service docker start

Finally, check to make sure the installation was successful:

docker run fedora /bin/echo hello world

Your command line should return a message reading hello world.

If you want to launch Docker automatically whenever you start up your system, you should enter this command as well:

chkconfig docker on

On Ubuntu, start by typing this command instead:

apt-get update
apt-get upgrade

Then, install the AUFS file system by entering:

apt-get install linux-image-extra-`uname -r`

This should return the following message:

A new version of /boot/grub/menu.lst is available, but the version installed
currently has been locally modified.

What would you like to do about menu.lst?

Add your Docker repository key using the following command:

apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Next, add your Docker repository to your Advanced Packaging Tool (APT) sources list:

sh -c "echo deb https://apt.dockerproject.org/repo ubuntu-trusty main > /etc/apt/sources.list.d/docker.list"

Then, install Docker with this command:

apt-get update
apt-get install docker-engine

Finally, check to make sure it’s been installed:

docker run ubuntu /bin/echo hello world

After that, you just need to look for the hello world return message to confirm that everything is working properly.

Conclusion

Deploying web applications using virtual machines can be challenging for a number of reasons. They’re difficult to scale to multiple servers, and can face problems with performance and portability.

Docker is a flexible solution that tackles these issues through the use of containers. In this post we discussed three advantages of using Docker, including:

  1. It provides increased scalability through the use of its swarm mode.
  2. Using it can improve your application’s performance.
  3. You can streamline portability between servers to make deployment easier.

 

Featured image: Unsplash.