From the course: Docker: Build and Optimize Docker Images
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Combining commands and maintaining readability - Docker Tutorial
From the course: Docker: Build and Optimize Docker Images
Combining commands and maintaining readability
- [Instructor] When you write a Dockerfile, every from, workdir, run, copy or add instruction creates a new layer in the final image. We can reduce the number of layers that are built by combining instructions in the Dockerfile. Here, I'm in VS Code, and I have our Dockerfile open. Let's build our image so we can view the layers in the output. Open a terminal and type docker build, the -t flag, then the name and version of our image, which is 2.3.3, and then end with a period for the build context. The layers are numbered in the output, and you can see that we currently have eight layers. There are separate layers for the from, workdir, copy, and run instructions from the Dockerfile. Let's take a look at the Dockerfile to see what instructions we can combine. If you look at the run instructions to create a non-route group and user, you'll see that there are two separate instructions. We can group these together because they're related, so we don't need separate layers for both. On the…