Why should I use Containers in CI/CD?
Containers have been around for a long time, and it’s hard to imagine today’s devops world without them. But why is container technology so popular with sysadmins and developers? Well, containers help you to build your code, test it in any given environment, and – this is probably the best feature – help you to catch bugs early, before you release it. In short: containers are a great idea if you’re looking to standardize deployments, even across multiple machines and platforms.
So, what’s special about containers and why should you include containers in your Continuous Integration/Continuous Delivery pipeline? In this article we’ll look at containers and how they differ from virtual machines. I’ll also explain how to use containers in DeployBot, how to customize the Docker containers available in DeployBot, as well as how to create and include your own.
What are Containers?
Put simply, a container is an executable piece of software which provides an entire runtime environment, including applications, libraries, configuration files, and more – everything you need to build your code and test it, bundled in one package. Containers are virtual runtime environments, running on top of an operating system’s (OS) kernel. The container process is isolated from other processes, i.e. it gets resources assigned, which other processes cannot access.
This also works the other way round: containers don’t have access to resources which haven’t been explicitly assigned to them. Now, the idea of isolated environments isn’t that new – it goes back to the Unix operating systems of the 1970s and the chroot environment. It changes the root directory for a process, including the process’ children, so that programs can run in a safe and contained environment. Containers follow the same idea: isolate applications and processes, files, network devices, etc.
What’s the Difference between Virtual Machines and Containers?
Containers are often compared to virtual machines (VMs), but they’re actually quite different, even if they have the same purpose: isolate an application and its dependencies into a self-contained unit that can run anywhere. In VMs, a guest operating system runs on top of a host operating system, and they share the underlying hardware. A so-called hypervisor virtualizes the physical hardware and orchestrates the available resources, i.e. hard drives, memory, network interfaces, etc. In other words, a VM is a replica of the physical environment, and as a result you’re limited to the physical resources available.
Containers don’t virtualize the underlying hardware, and unlike virtual machines they don’t include a “real” guest operating system. Instead, they virtualize at the operating system level and rely on an underlying image with some basic programs. Those container images are basically snapshots, based on a system’s filesystem.
Containers use the features and resources of the host OS and the images only contain the application, the libraries and other dependencies. They share the kernel of the host OS with other containers (read-only). There is no way to create a container which uses a different kernel. As a result, containers are lightweight, fast and portable – you can deploy multiple containers on a single machine and have only one operating system to look after. Containers can run anywhere, on your desktop computer, on servers, and in the cloud.
Containers in DeployBot: Hello, Docker!
There are many different container formats available – one of the most popular ones is Docker, which has been around since 2013. Responsible for the development of the Open Source container toolkit is the company of the same name, Docker Inc. As a DeployBot user you don’t need to learn how to install and configure Docker. We offer three default Docker containers which you can easily include in your CI/CD pipeline. All of them contain useful tools like PHP, Node.js, Python, Java, etc.
Want to learn more about our Docker containers and how to customize them? DeployBot is here to help you.
If you’re not happy with the OS image (Ubuntu 18.04, 16.04, and 14.04) or the installed software in our containers, you basically have 3 options:
- You can customize an existing Docker container in DeployBot by changing its configuration.
- You can use another container image from Docker Hub.
- You can build your own Docker container image, upload it to the Docker Hub library and pull it from there.
In DeployBot, you can modify existing containers or create custom containers in your account’s Settings, section Containers. Everything you configure here can easily be re-used in all servers of your account. Container best practices suggest that you only include components in your containers which you really require. That keeps the images lightweight and doesn’t waste unnecessary resources.
Implementing your CI/CD Pipeline
So, how exactly do containers fit into all the steps which happen when delivering new applications? First of all, developers push their code changes to GitHub, GitLab, or Bitbucket. DeployBot detects the changes and triggers an automatic deployment (for example in staging environments). Alternatively, you manually deploy which is recommended for production systems. To include a Docker container to compile, test or process the code otherwise, you select the Compile, compress, or minimize your code option in your server’s configuration.
Next, you enter the build commands which run inside the Docker container. Only if the build is successful, the deployment to your server goes along. Otherwise, the deployment will stop and will be marked as failed.
Pros & Cons of Containerization
Although there are situations where you might want to use a different approach, containers can be really useful. Apart from keeping the development costs down, they allow you and your fellow developers to run parallel tests in safe environments and therefore save time on the build process of your applications.
One disadvantage often mentioned in relation to containers is the setup process, as it requires some (Linux) skills – a problem that can easily be avoided with a tool like DeployBot. We’ve taken care of building containers, and they provide software needed by most web developers. If they don’t meet your needs, feel free to modify them or include a container from Docker Hub, as you see fit.