How to do it...

Let us build a concept of distributed setup for our Department, Employee and Login microservices by following these steps:

  1. Before the entire configuration, download and install Docker Toolbox from https://www.docker.com/products/docker-toolbox to avoid lots of complicated Docker configurations. The toolbox will provide us a VirtualBox and a client to manage our images. Also, it will automatically setup .dropbox session details for global access to its CLI commands in the Windows operating system.
  2. Install the Docker Toolbox and sign up for a free account to create your docker-machine using Kitematic:
  1. Log in to view your Kitematic dashboard. Once online, you can search for free Docker images and install them through your dashboard. Also, your dashboard will keep a list of all installed images in your docker-machine. On the lower left of the dashboard, you will find a button that will invoke the CLI window:
  1. Now, go back to Spring Boot development. Modify the previous ch10-deptservice, ch10-empservice, and ch10-loginservice so that these can be dockerized into the docker_machine. To avoid conflicts, create exact copies of each project with Maven project names ch10-dept-docker, ch10-emp-docker, and ch10-login-docker.
  2. Since the microservices use MySQL server, add a mysql-server image through the Kitematic account and run the following CLI Docker command with the needed database credentials to boot up the MySQL image:
docker run --name mysql-server -e MYSQL_ROOT_PASSWORD=spring5mysql -e MYSQL_DATABASE=hrs -d mysql:5.6 
  1. Among the three microservices, let us first Dockerized ch10-dept-docker. Inside the project, create a folder src/main/docker, and drop a Dockerfile. This configuration file is an image structure of the Docker image where the Spring Boot application will be deployed. It has sensitive Docker image information which is found below:
FROM java:8 
MAINTAINER [email protected] 
EXPOSE 8080 
CMD java -jar ch10-depty-docker.jar 
ADD ch10-depty-docker.jar ch10-depty-docker.jar 
ENTRYPOINT ["java","-jar","ch10-depty-docker.jar"]
The correct filename must be Dockerfile and without any extension. Changing the case will cause an error during Docker deployment.
  1. Afterwards, add the current version of docker-maven-plugin to the <plugins> of pom.xml:
<plugin> 
     <groupId>com.spotify</groupId> 
     <artifactId>docker-maven-plugin</artifactId> 
     <version>1.0.0</version> 
     <configuration> 
             <imageName>${docker.image.prefix}/${project.artifactId} 
</imageName>                                 <dockerHost>https://192.168.99.100:2376</dockerHost> 
                          <dockerCertPath>C:/Users/sjctrags/.docker/machine/certs 
</dockerCertPath> 
          <dockerDirectory>src/main/docker</dockerDirectory> 
          <resources> 
              <resource> 
   <targetPath>/</targetPath>   
                    <directory>${project.build.directory}</directory> 
<include>${project.build.finalName}.jar</include> 
              </resource> 
          </resources> 
      </configuration> 
</plugin> 
To see the host information of your docker_machine, open a Docker CLI and run the command docker-machine URL to extract the IP address and the port of the Docker machine. Moreover, Docker machine can be accessed only using HTTPS thus .pem certificates found in its repository are needed to be accessed by Maven.
  1. Before the deployment, the last configuration is to change <packaging>war</packaging> to <packaging>jar</packaging>. Docker images are built through JAR files.
  2. Finally, run the Maven command clean package docker:build to download all the necessary dependencies and execute the Dockerfile. The whole process must end with a BUILD SUCCESS.
  3. Check your Kitematic account; both the mysql-server and ch10-dept-docker images must now be uploaded:
  1. Run the image through CLI commands or by clicking the CREATE button of the image:
  1. Open a browser and run all the controller requests.
  2. If the error https://192.168.99.100:2376: Connection reset by peer: socket write error is encountered, just try to restart the Docker machine through docker-machine restart command.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.70.38