InterviewSolution
| 1. |
What are the basic instructions used in Dockerfile and how they differ from each other? |
Answer»
Usage : FROM <image> [AS <name>]Or FROM <image>[:<tag>] [AS <name>]Or FROM <image>[@<digest>] [AS <name>]FROM helps to set the base image for the following instructions in the Dockerfile. The base image COULD be one pulled from the remote public repository or a local image built by the user. FROM can appear multiple times in Dockerfile and each time it appears it clears any stage created from previous instructions. Hence usually an AS <NAME> is added to the FROM instruction to identify the last image created just before the FROM instruction.
Usage:
RUN instruction creates a new layer on the current image which is USED for the next step in Dockerfile.RUN cache is valid for the next build provided “docker build” command is not run with “--no-cache” flag. RUN in the executable form doesn’t do shell processing like variable substitution.
Usage:
CMD provides defaults for executing container. There could only be one CMD instruction but if there are many, only the last one has the effect. If CMD is providing default arguments for the ENTRYPOINT instruction, then the CMD and ENTRYPOINT instructions should be specified with the JSON array format.
Usage:
The ADD instruction copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the image at the path <dest>.
Usage:
The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>.Main difference between COPY and ADD is that ADD supports the source to be a URL or TAR file.
Usage:
An ENTRYPOINT allows you to configure a container that will run as an executable. As a best practice ENTRYPOINT should be defined when using the container as an executable and CMD should be used as a way of defining default arguments for an ENTRYPOINT command.CMD could be overridden while running a container with arguments.
Usage:
|
|