3. Best Practices for Optimising Docker Images Flashcards
Why is it important to understand the anatomy of Docker images?
Understanding how Docker images are constructed is key to managing their size.
Where is the configuration data for an image located in the result from the docker inspect
command?
Inside the top-level Config
object.
{ ... "Config": { ... } ... }
Where is the working directory path for an image located in the result from the docker inspect
command?
Inside WorkingDir
field of the top-level Config
object.
{ ... "Config": { ... "WorkingDir": ".", ... }, ... }
How can we inspect a Docker image?
By running the docker inspect
command with the image’s tag or id.
docker inspect mini:1.0
Where is the filesystem definition for derived containers located in the result from the docker inspect
command?
Inside the top-level RootFS
object.
{ ... "RootFS": { ... } ... }
Where is the content layers information for the image located in the result from the docker inspect
command?
Inside the Layers
field of the top-level RootFS
object.
{ ... "RootFS": { ... "Layers": [ ... ], ... } ... }
What are the three types of Dockerfiel instructions?
- Instructions — Dockerfile instructions define the content and nature of images.
- Metadata — instructions that define how derived containers will get executed.
- Content — instructions that create files and directories for the image.
What are the three content-creating Dockerfile instructions?
- COPY — used to copy the build context into an image.
- ADD — similar to COPY instruction, but can retrieve remote content.
- RUN — executes commands to generate additional image content.
What are the three content-creating Dockerfile instructions?
- COPY — used to copy the build context into an image.
- ADD — similar to COPY instruction, but can retrieve remote content.
- RUN — executes commands to generate additional image content.
What are the three content-creating Dockerfile instructions?
- COPY — used to copy the build context into an image.
- ADD — similar to COPY instruction, but can retrieve remote content.
- RUN — executes commands to generate additional image content.
What are the three Dockerfiel instructions that add a new content layer to the image?
COPY, ADD, and RUN.
Which is the recommended method of copying content from the build context into the image context, COPY or ADD?
COPY wherever we can.
What does Docker do with the layers created by content-creating Dockerfile instructions?
When a container is created, Docker assembles the content of each of the image layers to present a homogenous set of files and directories. This forms the basis of the container filesystem.
What can be said about the mutability of a Docker image?
The content of the images is read-only and in this way, Docker achieves immutability for images.
What can be said about the duplication/sharing of a Docker image’s content when creating other images or building containers from it?
We can build images from other images and build containers that all share the same content without having to duplicate everything due to the immutable nature of containers and images.