CI/ CD with Docker and Kubernetes Book

Categories:

Recommended

Using Docker for Development and CI/CD 

In 2013, Solomon Hykes showed a demo of the first version of Docker during the PyCon conference in Santa Clara2. Since then, the benefits of Docker containers have spread to seemingly every corner of the software industry. While Docker (the project and the company) made containers so popular, they were not the first project to leverage containers out there; and they are definitely not the last either.

Several years later, we can hopefully see beyond the hype as some powerful, efficient patterns emerged to leverage containers to develop and ship better software, faster. In this chapter, you will first learn about the kind of benefits that you can expect from implementing Docker containers.

Then, a realistic roadmap that any organization can follow realistically, to attain these benefits.

1.1 Benefits of Using Docker 

Containers will not instantly turn our monolithic, legacy applications into distributed, scalable microservices. Containers will not transform overnight all our software engineers into “DevOps engineers”. Notably, because DevOps is not defined by our tools or skills, but rather by a set of practices and cultural changes. So what can containers do for us?

1.1.1 Set up Development Environments in Minutes 

Using Docker and its companion tool Compose, you can run a complex app locally, on any machine, in less than five minutes. It sums up to:

$ git clone https://github.com/jpetazzo/dockercoins
$ cd dockercoins
$ docker-compose up

You can run these three lines on any machine where Docker is installed (Linux, macOS, Windows), and in a few minutes, you will get the DockerCoins demo app up and running. DockerCoins was created in 2015; it has multiple components written in Python, Ruby, and Node.js, as well as a Redis store. Years later, without changing anything in the code, we can still bring it up with the same three commands.

This means that onboarding a new team member, or switching from a project to another, can now be quick and reliable. It doesn’t matter if DockerCoins is using Python 2.7 and Node.js 8 while your other apps are using Python 3 and Node.js 10, or if your system is using even different versions of these languages; each container is perfectly isolated from the others and from the host system.

We will see how to get there.

1.1.2 Deploy Easily in the Cloud or on Premises

After we build container images, we can run them consistently on any server environment. Automating server installation would usually require steps (and domain knowledge) specific to our infrastructure. For instance, if we are using AWS EC2, we may use AMI (Amazon Machine Images), but these images are different (and built differently) from the ones used on Azure, Google Cloud, or a private OpenStack cluster.

Configuration management systems (like Ansible, Chef, Puppet, or Salt) help us by describing our servers and their configuration as manifests that live in version-controlled source repositories. This helps, but writing these manifests is no easy task, and they don’t guarantee reproducible execution. These manifests have to be adapted when switching distributions, distribution versions, and sometimes even from a cloud provider to another, because they would use different network interfaces or disk naming, for instance.

Once we have installed the Docker Engine (the most popular option), it can run any container image and effectively abstract these environment discrepancies.

The ability to stage new environments easily and reliably gives us exactly what we need to set up CI/CD (continuous integration and continuous delivery). We will see how to get there. Ultimately, it means that advanced techniques, such as blue/green deployments, or immutable infrastructure, become accessible to us, instead of being a privilege of larger organizations able to spend a lot of time to build their perfect custom tooling.

1.1.3 Less Risky Releases 

Containers can help us to reduce the risks associated with a new release.

When we start a new version of our app by running the corresponding container image, if something goes wrong, rolling back is very easy. All we have to do is stop the container, and restart the previous version. The image for the previous version will still be around and will start immediately.

This is way safer than attempting a code rollback, especially if the new version implied some dependency upgrades. Are we sure that we can downgrade to the previous version? Is it still available on the package repositories? If we are using containers, we don’t have to worry about that, since our container image is available and ready.

This pattern is sometimes called immutable infrastructure, because instead of changing our services, we deploy new ones. Initially, immutable infrastructure happened with virtual machines: each new release would happen by starting a new fleet of virtual machines. Containers make this even easier to use.

As a result, we can deploy with more confidence, because we know that if something goes wrong, we can easily go back to the previous version.

Category:
Tag:

Attribution

Rendered Text (2022), CI_CD with Docker and Kubernetes Book, URL: https://github.com/semaphoreci/book-cicd-docker-kubernetes

This work is licensed under Attribution-NonCommercial-NoDerivatives 4.0 International License  (https://creativecommons.org/licenses/by-nc-nd/4.0/).

VP Flipbook Maker

This is a book converted and displayed with VP Online Flipbook Maker. It is a professional tool for digital flipbook conversion and creation. Try it now!