 Okay in this video, we're going to go ahead and configure the Docker file for a layered build. I'm going to collapse that down and what I'm going to do is I'm going to create another folder called Docker and this will come into play later on in this course where we'll be using a build tool with Maven to build Docker. So I'm just going to make that Docker and we'll come in and add in a Docker file and add this to get and Normally you wouldn't have two different folders for Docker. You'd only have one Docker file But for the purposes of the course, I want you to be able to compare and contrast between having a slim regular traditional Docker file and then also the layered Docker file So now we are actually building the layered Docker file and what I want to do is I want to come in and This is going to be a multi-stage build meaning that we will have two Docker Images start up. So one will build and we're going to be using that to run a command to extract out the layers and then the second one is going to be the actual Docker file that we're using for our image and We'll take the layers from the first one and copy those over. So let's take a little closer look as to what we're doing here Again, we just need that and we are going to call this as a builder So that is we're using this as a a builder image You know work dirt is going to be application is just fine and here I'm going to use the add command add and copy are very similar and Here I'm going to say target. We're going to get to the Directory a little bit different again, we want to take that a jar file and that's going to be KBE So that is going to add that in and here what we want to do is say run Java minus D jar mode equals tools Dot slash there And if I mistyped something we're going to copy it over. So we're gonna say minus jar So this is a Java command. We are saying use the layer tools to extract out the layers So that's all we want from this first builder So inside this image, it's going to start up as a container It's going to take in and we'll add in that target the jar file And we are using the layer tools to extract out those layers now. We're going to say from Open JDK. We'll use the same one JRE slim And we can use application is just fine And now we're going to say copy And actually I'm going to copy this over from my working notes It's going to speed up. I don't think you guys want to see me type all this out So I'm going to cut and paste this in So now you can see that we're saying copy from builder So that's doing a reference to this image saying from builder from the directory application Dependencies and we're going to bring those into our application. So this here is the first container that we're starting up and then this is the image that we are building and Note here that we have the four layers that we are copying. So we have dependencies spring boot loader snapshot dependencies, which is typically going to be empty Then the application and then the entry point and the entry point now We are going to use the spring boot loader the jar launcher. So slightly different. That's what allows all the class paths and stuff to get reassembled in this and before we actually try to build this remember Here we added in that maven configuration to do the layers. We want to do a clean on our project Now we can say go ahead and do a package step Now package things up with the new layers being built and while that's building we want to do this So I'm giving you that Docker command and now it's not Docker base. It's just going to be Docker And so it's the same commands, I'm going to copy that command and we'll take that into terminal So now rather than Docker base we are going Docker Docker file and we'll tag that to kbe rust again and See that we did have everything build properly and you can see here that we are doing the Multiple stages of the copy and then writing the image and you can see that's coming up cash That's because I ran up previously in my my testing if anything changed. It would have changed there just double checking everything and Now if we do Docker ps you can see that I still just have Postgres running. Let's do a Spec down this we can do Docker history And that'll be kbe rust that is our tag And here which you can see this is a history of that image And these lines down here that that is all from the base image. So that is from the JRE image so you can see that that's got a number of layers now we have a worker of application and Here you can see the actual dependency. So our dependencies. So that's 41 meg. That's a good chunk of data That is all our that's the fat jar dependency So all the various jars and that's actually pretty slim for a spring boot project So as you get into larger projects and having more complex applications that can grow significantly Then our spring boot loader that is pretty light snapshots and then there's our application. You can see that's only 90 kilobytes So if we were deploying this running multiple versions of our application and pulling that over and over and over Rather than having all this get copied into a single image now These files here are going to be staying the same. They'll get reused So if I have four applications running on the JRE These are all going to get reused automatically because we're using that JRE image if we have the exact same dependencies These will get reused and then only this one is going to be changing. So very very important Let's if you start living with Docker on machines You do realize that if you are tight on disk space It can really chew up a lot of disk space and this is a way to really make your Disk utilization by Docker a lot more efficient. So this is going to be a lot more efficient for Building and deploying applications in either a test or some type of production deployment environment So the layers that the Spring Boot team came up with it's a pretty clever way of saving yourself a lot of disk space and a lot of ongoing maintenance and having to go back and and clean up the old layers that you may have on your system