Build an image
docker build
Enter the following command:
You should see output like the following:
Here's what happened when you ran the command:
Docker parses the Dockerfile. If there are any errors, the build will exit with an error.
In the
=> [1/2]
step, Docker processes the first instruction. It determines that thealpine
image is not stored in the machine's image cache, so it pulls it from Docker Hub. Each of the following lines until the next instruction reflect a layer of thealpine
image that is being fetched and cached. There is a one-to-one correspondence between every instruction in a docker file and the layer that is generated. The image cache significantly improves fetch performance and well as reduces the amount of storage required when using images that share ancestor images.In the
=> [2/2]
step, Docker performs theCOPY
instruction, copyinghello.sh
from the build context into the image.Finally, in
=> exporting to image
, Docker creates the image and names it.
You can view the final result with the docker image ls
command:
Output:
You can inspect more details with the docker inspect
command:
Output (shortened for space):
The important things to note here to reinforce your understanding at this point are:
Config - this defined the container's environment when it launches.
You can confirm here that the entrypoint for a container is
/hello.sh.
ContainerConfig - only mentioned to point out that every instruction in a Dockerfile actually runs in its own container while building each corresponding image layer; this is the Config for the "build" containers.
RootFS - you can confirm here that the two instructions processed for writing to the image file system (
FROM
andCOPY
) resulted in the two layers of the file system.
Keep in mind that the container's file system, as composed by all the image layers, must in general provide all the file dependencies a containerized process will need when it runs -- it does not have access to the host's file system unless you explicitly mount a file or directory into it for certain types of scenarios (such as a persistent cache).
Last updated