Changing the Way of Continuous Delivery with Docker (Part 2)

Introduction

Docker is a service that has reformed the way of conducting continuous delivery. Docker allows you to package an application with all of its dependencies into a standardized unit for software development and guarantees that the software will always run the same, regardless of its environment. The first part of this series gave an outline of the overview, challenges, and environment and build requirements for using Docker. This post will explore the specific methods for using Docker along with the delivery processes.

How to Use Docker

Step 1: Installing the Docker runtime environment

The Docker runtime environment has only one limitation, that is, the Linux operation kernel must be higher than version 3.10. Docker provides a convenient method to install and setup a Docker environment on your machine using Docker Toolbox. This installer allows you to easily install Docker regardless of the underlying OS. It also supports a variety of cloud servers, including Alibaba Cloud's Elastic Computing Service (ECS) servers.

Step 2: Using Dockerfile to describe the application environment

  • Method 1:

O&M personnel need to list all items originally required for building an environment and describe them with the Dockerfile. Dockerfile is not a development language, but only a defined description language. To create a description language, you must include the FROM instruction and an environment in the FROM. When this is defined, the user can perform tasks with roles and responsibilities assigned, including running for executing commands, event as an environmental variable, as well as add, expose, and cmd commands.

  • Method 2:

Upon successful establishment of a standard Java environment, one can use it directly by applying jar to it.

If services are disassembled into micro-services (each service is not a war package but a jar), then all the micro-services should share a common Docker image. Many languages have the API function, and in most cases do not require dependencies but require the running environment of the language.

Docker images for varied environments are available at many official websites. You can use images from the FROM official website directly by applying jar to them. Further, some open source software allows the user to run them directly after being downloaded, such as Gitlab. With the Docker technology, it also becomes much easier to build several open source tool systems.

Step 3: Using Docker to build compiling/unit testing environments

  • Separated compiling of applications and Docker environments

When compiling applications and Docker environments together, it is necessary to copy the application code to the Docker environment. However, during the process of building a Docker environment, if application code is built within the Docker environment, they will be deleted. Given the hierarchical structure of the Docker (with harmonized uppercases and lower cases throughout a context), any .java copied to the Docker file for building a jar will be deleted after the jar is built. Since access to the source code is simply via the .java. Besides this, the code is undesirable in a production environment when the Docker container runs over there.

  • Separation of the compiling and testing environment

Based on the minimum Docker image principle (installing only what is essential), a Java (harmonized uppercases and lowercases) + NodeJS running environment does not require ping after a production environment starts to run, and is only necessary for debugging during O&M. Compiling may depend much more on the compiling environment, but the running of a production environment does not require dependencies. Therefore, we recommend separating the environments, and creating a compiling environment also by using Docker.

A compiling environment is only for building, while a testing environment is only for running. The process of using an environment for building procedures follows this simple principle:

Code uploading can proceed by using the -v method to a container called "build", where you can use different languages for building files such as binary dependency packages; then add these files to the Docker file for the Docker build. Through the two steps of building, you will successfully build Docker images that can run.

Other than source code, binary created through the first step of building and added to the Docker file is also run.

After building an image, you can activate different scripts, such as activating a production script for running production, or activating a testing script for running a test. You may use Docker to run an integrated test as well. For a Dockerized application, once a Docker is run for executing a test command, it will execute a testing process, regardless of whether it is a database or not. Anything that can be scripted for testing can be written with Docker.

Step 4: Using Docker to describe dependencies on environment

An application cannot do with only images but also depends on a database, if not another application. For example, a database is necessary when performing data testing.

Docker also offers a tool called Docker Compose, which can manage multiple Docker images. Refer to the following steps to use Docker Compose:
1. Write a Docker file to describe an application environment
Describe what a project directory is in the Docker file, copy a requirement file to and under the code directory, pip install a ruby program, and run the program.
2. Use .yml to describe the dependency
In most circumstances, using a single container does not solve most problems. You can use .yml to describe one or more web applications, databases, and others.
When an application needs to depend on a database, you can write a link and name it "link DB". By using the Docker Compose command, you will be able to run a group of Docker images, and you will be able to describe the dependencies therein using compose .yml.
3. Use Docker to describe the whole integration or the running environment
After Docker is up and running, the app may need a load balancer, database, file storage, cache, or other items.

  • Database
    Docker does not care about the location of creation of a database or the means of its creation. During a development control process, if you need to start a DB, you will have to pull the DB container from the corresponding official source. For example, when you need to use a MySQL DB5.7, start the container of the MySQL DB to view the corresponding configuration, or when necessary, to modify some language descriptions. You can run it in Docker Compose. Write dependencies in the first line to run MySQL 5.7; write environmental variables in the second line to replace the configuration files with its own; set up the start password and then start the port at 3306 or otherwise.
    To test a web application, you do not need to write a MySQL ID, and only MySQL may do as the MySQL described in "compose". Then obtain access to the database by entering the password. For Redis, you only need to name it and provide the port, and it only needs the cache service.
  • Load Balancer
    Load balancing is also simple, and nginx and Haproxy both offer official tools. The greater concern for developers is using Docker to describe their applications. After completing a description, run the app by completing the "compose" and specifying the version and configuration of nginx.
  • Storage
    Mount on the host machine using -v, and then store the database and initialized data under a local directory. This allows you to click on the app rather than initializing it upon each time of running.
    During the running of a production environment, data storage takes place in a cloud server, regardless of the implementation. No matter whether you have used NAS or Alibaba Cloud Object Storage Services (OSS), you can put together a directory under a local directory, instead of uploading the data using SDK or API to a cloud storage device.

Dockerized Delivery Process

In addition to code, configuration, and test scripts, developers also need to write the Dockerfile. Upon pushing the code to a code repository, the CI service will tell a new commit via the code repository hook. It will then pull and copy the Code for build and UT. During the build process, it will pull the image on which it depends from the Docker Registry; once the build process is complete, it will push the image to the Docker Registry unit. Then CI will have a hook to inform CD, and the Deploy Service will deploy the image to a pretest, test, or production environment based on the Docker, image description, and compose description.

The whole deployment process is to pull a build-ready image from the Registry and run it. Since the most complicated content is in the image and "compose" files, the whole process is simplified.

Conclusion

1. What does Docker delivery bring?
It makes development clearer and more flexible to developers. Previously, the concern was on Java dependency, and it was quite hard to build a Java environment locally. However, now that concern has shifted to the dependency of the whole environment, it makes Java environment build much easier. With this approach, O&M personnel no longer need to change their schedule due to software dependencies, and do not have to constantly change the configuration. What can Docker be applied to? Every project and environment for everyone. It is also the most effective implementation of DevOps. With Docker, you can apply programming to operations and manage environmental operations using development practices.

2. What scenarios should be Dockerized?
Complete definition related to this is yet to emerge. However, my understanding is that the greatest benefit of conversion into a container is the realization of shorter life cycles and statelessness. For example, for web applications such as REST API or CI/CD, you can pull the whole Docker container for running during a test, and then discard it after the test is complete to avoid resource occupation. In a task-performing process, you can save on resources by using Docker.

Databases, especially those for storage, are the most difficult to Dockerize, and thus may not directly benefit from containers. If a server bears a much greater load, it serves as file storage. However, this does not mean it is not doable, but may be of little significance.

时间: 2024-10-07 13:29:47

Changing the Way of Continuous Delivery with Docker (Part 2)的相关文章

Changing the Way of Continuous Delivery with Docker (Part 1)

Introduction This post is the first part of the series "Changing the Way of Continuous Delivery with Docker" and discusses the background, challenges, and processes involving Docker. Docker is a service for reformed continuous delivery. In the s

持续交付系列(二):使用Docker、Mesos实现持续交付

本文讲的是持续交付系列(二):使用Docker.Mesos实现持续交付,[编者的话]本文主要介绍Mesos和Marathon的搭建以及如何完成整个持续交付过程,以及后续还可以做哪些改进和加强.整个系统搭建完成后,应用代码的改变会自动触发Jenkins构建流程,几秒钟后,改变就会通过Jenkins.Docker Hub和Marathon传递到Mesos中部署上线,是不是很酷? 第一部分(中文翻译)我们介绍了如何Docker化一个Node.js应用,如何使用Fig部署Jenkins和Docker R

持续交付系列(一):使用Docker、Mesos实现持续交付

本文讲的是持续交付系列(一):使用Docker.Mesos实现持续交付,[编者的话]本文主要讲述如何为Node.js应用搭建持续集成环境.包括如何在开发机器上Docker化一个Node.js应用,如何部署Jenkins和Docker registry以实现持续集成.推荐对使用Docker做CI方面的工作感兴趣的同学阅读,CI也是Docker的应用场景之一,本文是很好的教程. 你首先需要在你的Linux机器上安装Docker和Fig.本文主要会介绍如何使用Docker和Mesos实现持续集成. 测

从代码到上线, 云端Docker化持续交付实践

关于分享者: 罗晶,花名瑶靖.在加入阿里云之前,先后在支付宝平台数据技术事业群.百度基础架构部任职.现主要负责阿里云容器服务产品的集群管理系统的研发,从事容器的持续交付.持续集成的方案设计与实现. 演讲内容架构 大话持续交付 持续交付的前世 容器化DevOps 持续交付的今生 演讲主要内容 持续集成指的是,频繁地(一天多次)将代码集成到主干.持续集成的目的,就是让产品可以快速迭代,同时还能保持高质量.它的核心措施是,代码集成到主干之前,必须通过自动化测试.只要有一个测试用例失败,就不能集成. 持

Docker在云平台上的最佳实践:基于容器技术的DevOps探索

12月9日,在云栖计算之旅线下沙龙上,阿里云容器服务团队的高级研发工程师秦妤嘉分享了<基于容器技术的DevOps探索>.首先介绍了DevOps和CD,接着分析了Docker如何打破传统CD壁垒,最后讲解了怎样从零开始搭建一个持续交付系统. 视频回顾 DevOps与Continuous Delivery DevOps 在一个较成熟的软件和服务交付的团队里,就技术层面来说主要分为三个组成部分:开发.测试和运维.开发测试团队比较关注的是代码能否运行,而运维比较关注的是系统能否在上线后稳定运行,于是隔

用Puppet和Docker构建工具来自动化容器产品部署

本文讲的是用Puppet和Docker构建工具来自动化容器产品部署[编者的话]本文介绍了最新版本的Puppet企业版支持的Docker自动化构建工具,包括了集成的Jenkins持续集成和部署以及支持新的编排系统. Puppet希望能将Docker构建工具纳入到自己的IT自动化管理中.新版本的Puppet企业版(Puppet Enterprise 2016.4)支持构建Docker容器,并自动部署到生产环境中. Puppet的最新版本是在Puppet的用户年会PuppetConf 2016上公布的

《Docker技术入门与实战》——3.3 搜寻镜像

3.3 搜寻镜像 使用docker search命令可以搜索远端仓库中共享的镜像,默认搜索Docker Hub官方仓库中的镜像.用法为docker search TERM,支持的参数包括: --automated=false仅显示自动创建的镜像. --no-trunc=false输出信息不截断显示. -s, --stars=0指定仅显示评价为指定星级以上的镜像. 例如,搜索带mysql关键字的镜像如下所示: $ sudo docker search mysql NAME DESCRIPTION

Kubernetes持续部署Docker Apps

本文讲的是Kubernetes持续部署Docker Apps[编者的话]本文是Codeship系列文章(Continuous Deployment for Docker Apps to Kubernetes)的第二篇,介绍了Codeship的相关配置项.如果已经等不及了,你可以下载电子书<Continuous Deployment for Docker Apps to Kubernetes> 这一系列文章中,我们介绍过了using Kubernetes for deployments.本篇我们

Thoughtworks Techniques

If you are wondering "What comes after agile?," you should look towards continuous delivery. While your development processes may be fully optimized, it still might take your organization weeks or months to get a single change into production. C