Author : MD TAREQ HASSAN | Updated : 2023/07/19
What is a container image?
- A container image is a packaging format that contains a set of files and meta-data (a bundle of multiple layers & metadata which provides extra information about the layers)
- Technically, A container image (in its simplest definition) is a file which is pulled down from a Registry Server and used locally as a mount point when starting Containers
- A container image is a portable package that, when run, becomes our container. The container is the in-memory instance of an image
- A container image is a ready-to-run software package, containing everything needed to run an application
- pplication code, its dependencies (libraries, runtime etc.) and configurations are packaged into a binary called a container image
- By design, a container is immutable: you cannot change the code of a container that is already running. If you have a containerized application and want to make changes, you need to build a new image that includes the change, then recreate the container to start from the updated image
- A container image is a bundle of files organized into a stack of layers that resides on your local machine or in a remote container registry
- Container images are read-only templates that define the application and its dependencies.
- Details: https://docs.microsoft.com/en-us/virtualization/windowscontainers/about/#container-images
Docker image is one of the container image formats.
About docker image
- A Docker image is a lightweight, standalone, and executable software package that contains all the necessary components to run an application
- It is the building block used to create and run containers in the Docker platform and also in the Kubernetes platform
- Docker image is designed to be portable and easily shared across different environments, making it straightforward to deploy applications consistently on various systems
Docker images have revolutionized application deployment and software distribution by simplifying the packaging and distribution process. They have become a standard way to package applications, making it easier for developers to build, share, and run applications in any environment that supports Docker. Normally, container images are stored in Container Registry (i.e. Azure Container Registry) and pulled from the registry while deploying.
docker build
- “
docker build
” is a command used in the Docker platform to build a Docker image from a Dockerfile - A Dockerfile is a text file that contains a set of instructions and configurations to define the steps required to create the image.
Command format
docker build [OPTIONS] PATH | URL | -
# Example
docker build --tag myapp:2.0 .
Build context & Dockerfile location:
- “
docker build
” requires 2 things:- Build context
- Dockerfile location
- “
docker build .
” means:- ”
.
” means current folder is the build context - Dockerfile is located in the current folder
- ”
[OPTIONS]
is additional flags and parameters that modify the build process. Some common options include:
-t, --tag
:- Name and optionally a tag in the
name:tag
format - Assigns a name and optionally a tag to the built image. This gives the image a human-readable name and version, like “myapp:latest” or “myapp:v1.0”
docker build --tag name:tag <Dockerfile location>
docker build --tag myapp:latest .
docker build --tag myapp:2.0 .
- Name and optionally a tag in the
-f, --file
:- Name of the Dockerfile (Default is PATH/Dockerfile)
- Specifies the path to the Dockerfile to be used for the build. By default, Docker looks for a file named “Dockerfile” in the build context directory
- By default the docker build command will look for a Dockerfile at the root of the build context
- The
-f, --file
, option lets you specify the path to an alternative file to use instead docker build . -f dockerfiles/Dockerfile.debug
- Build context (“
.
”): current folder - Dockerfile location: dockerfiles/Dockerfile.debug
- Build context (“
--no-cache
: Forces Docker not to use cached layers during the build, ensuring a fresh build from scratch- Details: https://docs.docker.com/engine/reference/commandline/build/#options
PATH | URL | -
- PATH :
- ”
.
” (current) or specify folder path - The build context directory containing the Dockerfile and any additional files required for building the image. The build context is sent to the Docker daemon during the build process.
- ”
- URL : URL parameter can refer to three kinds of resources - Git repositories, pre-packaged tarball contexts and plain text files
-
: To pipe a Dockerfile from STDIN