Home  >  Article  >  Operation and Maintenance  >  Detailed introduction to the build command in docker

Detailed introduction to the build command in docker

王林
王林forward
2020-07-20 17:38:559450browse

Detailed introduction to the build command in docker

The build command in docker is used to build a Docker image based on the given Dockerfile and context.

(Recommended tutorial: docker tutorial)

Docker build command usage format:

docker build [OPTIONS] <PATH | URL | ->

1. Commonly used OPTIONS options

--build-arg, set the environment variable during build

--no-cache, default false. Setting this option will not use Build Cache to build the image

--pull, the default is false. Set this option to always try to pull the latest version of the image

--compress, the default is false. Setting this option will use gzip compression to build the context

--disable-content-trust, the default is true. Setting this option will verify the image

--file, -f, the full path of Dockerfile, the default value is 'PATH/Dockerfile'

--isolation, default--isolation= "default", which is the Linux namespace; others include process or hyperv

--label, which sets metadata

--squash for the generated image. The default is false. Setting this option will compress the newly built multiple layers into a new layer, but you will not be able to share the new layer between multiple images; setting this option will actually create a new image while retaining the original image.

--tag, -t, the name and tag of the image, usually in name:tag or name format; multiple tags can be set for one image in one build

--network, default default. Set this option, Set the networking mode for the RUN instructions during build

--quiet, -q, default false. Set this option to Suppress the build output and print image ID on success

--force-rm. The default is false. Set this option to always delete the container in the intermediate link

--rm, the default is --rm=true, that is, delete the container in the intermediate link after the entire build process is successful

2, PATH | URL | - Description

gives the context within which the command will be executed.

The context can be the local path PATH where the build is executed, or it can be a remote URL, such as a Git library, tarball or text file, etc., or -.

During the process of building the image, you can use the ADD command to add any file in the context (note that the file must be in the context) to the image.

can be PATH, for example, the current local PATH is.

3. Example

docker build - < Dockerfile

Instructions: The above build process only has Dockerfile and no context

docker build - < context.tar.gz

Instructions : where the Dockerfile is located at the root path in the context.tar.gz package

docker build -t champagne/myProject:latest -t champagne/myProject:v2.1 .
docker build -f dockerfiles/Dockerfile.debug -t myapp_debug

The above is the detailed content of Detailed introduction to the build command in docker. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete
Previous article:What does Docker do?Next article:What does Docker do?