Docker For Java Developer : Understanding “EXPOSE” "FROM" "ENTRYPOINT" "ADD" in Docker file

Docker For Java Developer : Understanding “EXPOSE” "FROM" "ENTRYPOINT" "ADD" in Dockerfile
Docker builds images automatically by reading the instructions from a Dockerfile -- a text file that contains all commands, in order, needed to build a given image. A Dockerfile adheres to a specific format and set of instructions which you can find at Dockerfile reference.
A Docker image consists of read-only layers each of which represents a Dockerfile instruction. The layers are stacked and each one is a delta of the changes from the previous layer. The following is the contents of an example Dockerfile:
When building an image, Docker steps through the instructions in your Dockerfile, executing each in the order specified. As each instruction is examined, Docker looks for an existing image in its cache that it can reuse, rather than creating a new, duplicate image.
If you don’t want to use the cache at all, you can use the --no-cache=true option on the docker build command. However, if you do let Docker use its cache, it’s important to understand when it can, and can’t, find a matching image. The basic rules that Docker follows are outlined below:
Starting with a parent image that’s already in the cache, the next instruction is compared against all child images derived from that base image to see if one of them was built using the exact same instruction. If not, the cache is invalidated.
In most cases, simply comparing the instruction in the Docker file with one of the child images is sufficient. However, certain instructions require more examination and explanation.
For the ADD and COPY instructions, the contents of each file in the image are examined and a checksum is calculated for each file. The last-modified and last-accessed times of each file aren’t considered in these checksums. During the cache lookup, the checksum is compared against the checksum in the existing images. If anything has changed in any file, such as the contents and metadata, then the cache is invalidated.
Aside from the ADD and COPY commands, cache checking doesn’t look at the files in the container to determine a cache match. For example, when processing a RUN apt-get -y update command the files updated in the container aren’t examined to determine if a cache hit exists. In that case just the command string itself is used to find a match.
Once the cache is invalidated, all subsequent Dockerfile commands generate new images and the cache isn’t used.
At this point I would like you to understand the following key points based on the example file:
The Dockerfile is a text file that (mostly) contains the instructions that you would execute on the command line to create an image.
A Dockerfile is a step by step set of instructions.
Docker provides a set of standard instructions to be used in the Dockerfile, like FROM, COPY, RUN, ENV, EXPOSE, CMD just to name a few basic ones.
Docker will build a Docker image automatically by reading these instructions from the Dockerfile.
So from a developer, or tech user perspective you’ll be basically describing the build steps of your environment in the Dockerfile. Then you’ll build your image from the Dockerfile and start up your containers.
This also implies that understanding Dockerfile instructions is not enough to create your Dockerfile, because you need to also understand the context of the technology you are building for. If, for example, you are bulding a Dockerfile to be used in a PHP project, you’ll need to dive into PHP specific knowledge, like configuration methods, PHP extensions, environment settings and such.
The good news is that you can save a lot of time when starting out experimenting with a new technology, because you can use an image prepared by someone else, without understanding the details immediately. Once you are up for some more complex stuff you can start adding to the knowledge that you can extract and learn from other people’s Dockerfiles.
1# • Docker For Java Develo...
2# • Docker for Java Develo...
3# • SpringBoot With Amazon...
4# • Docker For Java Develo...
5# • Docker For Java Develo...
6# • SpringBoot With Amazon...
7# • Amazon RDS - Creating ...
8# • Deploying spring boot ...
9# • Jenkins Automation Par...
10# • Jenkins Automation Par...
Blog : hexortree.blogspot.in

Пікірлер

    Келесі