Reader small image

You're reading from  Mastering Spring Cloud

Product typeBook
Published inApr 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788475433
Edition1st Edition
Languages
Right arrow
Author (1)
Piotr Mińkowski
Piotr Mińkowski
author image
Piotr Mińkowski

Piotr works as a Solution Architect at Red Hat. He has several years of experience in software architecture and development. During this time, he was working in large organizations, where he was responsible for IT transformation to the modern cloud-native development approach. He is interested in technologies related to programming, containerization, and microservices. He writes about it in his blog https://piotrminkowski.com.
Read more about Piotr Mińkowski

Right arrow

Chapter 14. Docker Support

We have already discussed the basics of microservices architecture and Spring Cloud projects in the first part of this book. In the second part, we looked at the most common elements of that architecture and we discussed how to implement them using Spring Cloud. So far, we have talked about some important topics related to microservice migration, such as centralized logging, distributed tracing, security, and automated testing. Now, as we are armed with that knowledge, we may proceed to the final part of the book, where we will discuss the real power of microservices as a cloud-native development approach. The ability to isolate applications from each other using containerization tools, implementing continuous deployment in the software delivery process and the ability to easily scale an application are things that all contribute to the rapidly growing popularity of microservices.

As you will probably remember from earlier chapters, we have used Docker images for...

Introducing Docker


Docker is a tool that helps you to create, deploy, and run applications by using containers. It was designed with the view to benefit both developers and system administrators in accordance with the DevOps philosophy. Docker helps to improve the software delivery process by solving some important concerns related with it. One of those concerns is the idea of immutable delivery, which is related to something called it works for me. It is especially important that a developer uses the same image for their tests as the one that is used in production when working in Docker. The only difference that should be seen is during configuration. Software delivery in an immutable delivery pattern seems to be particularly important for a microservices-based system as there are many applications deployed independently. Thanks to Docker, developers can now focus on writing code without worrying about the target OS (where the application would be launched). The operation can, therefore...

Installing Docker


Docker installation instructions for Linux are specific to each distribution (https://docs.docker.com/install/#supported-platforms). However, sometimes you have to run a Docker daemon after installation, which you can do by calling the following command:

dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375

In this section, we will focus on instructions for the Windows platform. Generally, you have two available options when installing Docker Community Edition (CE) on Windows or Mac. The fastest and easiest way is by using Docker for Windows, which is available at https://www.docker.com/docker-windows. This is a native Windows application that provides an easy-to-use development environment for building, shipping, and running containerized applications. This is definitely the best option to utilize, because it uses Windows-native Hyper-V virtualization and networking. There is, however, one disadvantage—it is available only for Microsoft Windows 10 Professional...

Commonly used Docker commands


After installing Docker Toolbox on Windows you should run Docker Quickstart Terminal. It does everything that is needed, including creating and starting Docker Machine and providing the command line interface. If you type a Docker command without any parameters, you should now be able to see the full list of available Docker client commands with descriptions. These are the types of commands we will look at:

  • Running and stopping a container
  • List and remove container
  • Pull and push images
  • Building an image
  • Networking

Running and stopping a container

The first Docker command that is usually run after installation is docker run. As you may remember, this command is one of the most commonly used in previous examples. This command does two things: it pulls and downloads the image definition from the registry, in case it is not cached locally, and starts the container. There are many options that can be set for this command, which you can easily check by running docker run...

Creating a Docker image with microservices


We have already discussed the basic Docker commands that are available for running, creating, and managing containers. It's now time to create and build our first Docker image that starts the sample microservice that we introduced in the previous chapter. For that, we should move back to the repository available at the address https://github.com/piomin/sample-spring-cloud-comm.git and then switch to the branch feign_with_discovery  on https://github.com/piomin/sample-spring-cloud-comm/tree/feign_with_discovery. There, you will find a Dockerfile for every single microservice, gateway, and discovery. Before discussing these examples however we should refer to the Dockerfile reference to understand the basic commands that we can place there. In fact, Dockerfile is not the only way to build Docker images; we're also going to show you how to create an image with a microservice using the Maven plugin.

Dockerfiles

Docker can build images automatically by...

Continuous Delivery


One of the key benefits of migrating to microservice-based architecture is the ability to deliver software quickly. This should be the main motivation for implementing continuous delivery or a continuous deployment process in your organization. In short, the continuous delivery process is an approach that tries to automate all the stages of software delivery such as building, testing a code, and releasing an application. There are many tools that empower that process. One of them is Jenkins, an open source automation server written in Java. Docker is something that can take your Continuous Integration (CI) or Continuous Delivery (CD) processes to a higher level. Immutable delivery, for example, is one of the most important advantages of Docker.

Integrating Jenkins with Docker

The main goal here is to design and run the continuous delivery process locally using Jenkins and Docker. There are four elements that have a part in this process. The first of them is already prepared...

Working with Kubernetes


We have already launched our example microservices on Docker containers. We have even used CI and CD automated pipelines in order to run them on the local machine. You may, however, be asking an important question. How can we organize our environment on a larger scale and in production mode where we have to run multiple containers across multiple machines? Well, this is exactly what we have to do when implementing microservices in accordance with the idea of cloud native development. It turns out that many challenges still remain in this instance. Assuming that we have many microservices launched in multiple instances, there will be plenty of containers to manage. Doing things such as starting the correct containers at the correct time, handling storage considerations, scaling up or down, and dealing with failures manually would be a nightmare. Fortunately, there are some platforms available that help in clustering and orchestrating Docker containers at scale. Currently...

Summary


In this chapter, we discussed a lot of topics not obviously related to Spring Cloud, but the tools explained in this chapter will allow you to take advantage of migrating to microservices-based architecture. When using Docker, Kubernetes, or tools for CI or CD, there is an obvious advantage to cloud-native development with Spring Cloud. Of course, all of the presented examples have been launched on the local machine, but you can refer to these to imagine how that process could be designed in a production environment across a cluster of remote machines.   

In this chapter, we wanted to show you how simple and quick it can be to move from running Spring microservices manually on the local machine to a fully-automated process that builds the application from source code, creates and runs a Docker image with your application, and deploys it on a cluster consisting of multiple machines. It is not easy to describe all of the features provided by such complex tools as Docker, Kubernetes...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Spring Cloud
Published in: Apr 2018Publisher: PacktISBN-13: 9781788475433
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Piotr Mińkowski

Piotr works as a Solution Architect at Red Hat. He has several years of experience in software architecture and development. During this time, he was working in large organizations, where he was responsible for IT transformation to the modern cloud-native development approach. He is interested in technologies related to programming, containerization, and microservices. He writes about it in his blog https://piotrminkowski.com.
Read more about Piotr Mińkowski