If you’re a developer or involved with DevOps in any way, you’ve definitely heard of Docker. It’s one of the hottest technologies right now. Pretty much anyone who develops and deploys apps to the web can streamline their processes using Docker.
But what is all the hype about?
The Pain of Development Operations (DevOps)
As long as developers have been developing applications in one place and deploying them in another, DevOps has been a problem.
You know the feeling – you’ve developed an application that runs flawlessly on your local computer and you’re excited to get it to the world. You deploy it to your production server and… ERROR. You have no idea why, and the problem could be one of a million things. This problem is expensive, frustrating and ruins friendships between system administrators and developers around the world.
There a few technologies that attempt to solve this problem. The traditional way is with Virtual Machines, but the new and improved way is with Docker Containers.
I’m going give an overview of how you can how to deploy a web app with docker. We’ll take a look at what Docker is (and isn’t), what containers are, and how to use them.
What is Docker?
Docker is an open source technology that packages your applications into ‘Containers’. These containers hold all your application code, along with all its libraries and dependencies. You can then run this container on any machine running Docker, and it will run exactly the same, every time.
So how is it different from virtual machines?
Download Our Project Specification Template
This is one of the common misunderstandings with Docker. While a virtual machine appears to do something similar, it’s actually very different.
Virtual machines solve the same problem but in a different way. A virtual machine is a virtual instance of an entire operating system – maybe Linux or Windows. If you develop your app on a virtual instance of Linux, you can run that app anywhere that runs the same virtual instance of Linux.
Sounds good right? Yes, this does work, and it’s been used successfully for years. There is one problem, though – if you want to deploy a single web app, you need to run an entire virtual operating system. This is very expensive, especially if you have lots of apps to run.
Docker solves this problem by placing apps in virtual Containers that all run on the same operating system. Each container contains all the code, libraries, and dependencies needed to run the app. This saves us a huge amount of storage, time, processing power and complexity.
Why Would You Want to Use It?
The main selling points of Docker are
- Docker lets you get many more individual applications running on the same number of servers than other technologies
- It make developing encapsulated, ready-to-run applications a breeze – delivering everything in ‘containers’ that hold all libraries and dependencies for an app
- It makes the whole process of managing your applications and deploying them to live servers much easier and safer. You can edit an application, push the new docker image to a repository, then instantly run that application anywhere.
Put this all together and you have a very attractive product that can make your life (and your relationships with your sys admin) a lot easier.
Deploying A Web App With Docker Containers
Here’s the basic process of developing and deploying a web app with docker:
- Install Docker on the machines you want to use it
- Set up a registry at Docker Hub
- Create your Docker Image
- Set up your ‘Dockerized’ machines
- Deploy your application
Install Docker On Your Machines
Docker makes it easy to run applications anywhere, but those places need to have docker running. There are three main Docker variants, depending on how the type of environment you are setting up on:
- Docker Enterprise Edition (Docker EE)
- Docker Community Edition (Docker CE)
- Docker Cloud
It’s easy to install Docker on Mac, Windows, Linux, AWS and Azure. Once you have it up and running on all the machines you’ll be using, you are ready to get developing and deploying.
Check out the Docker installation manual for info on how to install it on your local machine and servers.
Set up a registry at Docker Hub
In order to easily distribute your applications, you’ll need somewhere to share them.
Docker Hub is like the GitHub of Docker Containers. There are thousands of apps and examples you can use. To set up your own public or private repository to start deploying your apps, just go to the Docker Hub website.
You can use Docker hub to push and pull changes of your app to different machines. There are also many tools to automate this process (more on this later).
Set up your ‘Dockerized’ Machines
The next step is to get your Docker environment ready to run your app. You do this by using the command line and a few different tools.
Read How We Helped a Marketing Company to Build a Back-Office Custom Ads Dashboard
These virtual machines are the ones responsible for setting up the Containers we have talked about. There are other really cool things you can do too, like setting up multiple instances of your app and use a load balancer to automatically send traffic to different versions across a cloud server.
Setting up on your local machine will be different to create Dockerized cloud servers. Check out the official Docker tutorial on the commands for your environment.
Create a Docker Image
Docker Containers are created from Docker Images. To get your app distributed to different machines, you’ll need to create a Docker Image to send to them. This is done using a Dockerfile
A Dockerfile is usually around 3-30 lines long and contains all the commands needed to create your Docker Image. There are infinite ways to set up you Dockerfile, it’s best to know docker deployment best practices before you set it up.
Here’s an example of a simple Dockerfile from the Documentation:
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
Check out the docs to find out what you need to put in your Dockerfile.
Once you’ve prepared your Dockerfile, you can use the build command line tool to create an image. Here’s an example of what your console might look like:
Deploy your application
Now you’ve got your Docker machines running, Docker Hub repository set up, and Docker Image built, you are ready to deploy the app across your machines.
First, push your application to your repository. You’ll find the docker login and docker push commands useful here. Check out an example of how it’s done here.
Next, pull your application from your repository to your other machines. You can do all of this with the docker run command. It will automatically find, pull, and run your new application.
That’s it! Those are the steps to use Docker to easily deploy an application to multiple machines.
Automate The Process
Obviously, you don’t want to be running all of those commands every time you make a change to an application. Luckily, there are many tools to use to streamline your workflow and automate the whole Docker application deployment process.
Some examples are:
- Google Kubernetes
- Docker Compose
- Lots more!
Get started with Docker, and you’ll get a feel for what parts you want to automate. The number of servers you have and type of app will determine your docker deployment strategy.
Getting Your Team On Board
Dev teams all over the world are flocking to use Docker. We use it here at DevTeam space to develop and deploy our client’s apps at lightning speed with minimal problems.
If your team isn’t already using Docker, it shouldn’t be hard to convince them. Finally, system administrators and developers won’t blame each other when an app won’t run properly in different environments.
Docker is a hot technology at the moment, and for good reason. Today we’ve had a glimpse of how to use Docker to deploy applications, make life easier, save money and time, and maybe even save a few friendships between system administrators and developers.
I’ve outlined the basic processes involved in getting a containerized app from your machine to live server or cloud environment. The actual steps you’ll take for your application will be a lot more detailed. Check out the documentation for information on how you can follow these steps for your app. Or, find a great dev team that can do the job for you.