# docker build 命令
該命令用于構建鏡像,與 Dockerfile 配合使用。
## 語法
```
docker build [OPTIONS] PATH | URL | -
```
## 常用參數
* -c:控制 CPU 使用
* -f:指定 Dockerfile 名稱
* -m:設置構建內存上限
* -q:不顯示構建過程的信息
* -t:為構建的鏡像打上標簽
## 實例
構建一個鏡像,命名為 hello,指定上下文目錄為當前目錄:
```
docker build -t "hello" .
```
構建一個鏡像,命名為 hello,同時指定上下文目錄為 test:
```
docker build -t "hello" ./test/
```
構建一個鏡像,命名為 hello,標簽為 new,同時指定上下文目錄為當前目錄,文件為 test 目錄內的 newfile,且不顯示構建過程:
```
docker build -q -f test/newfile -t "hello:new" .
```

## 幫助
```
$ docker build --help
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
Options:
--add-host list Add a custom host-to-IP mapping (host:ip)
--build-arg list Set build-time variables
--cache-from strings Images to consider as cache sources
--cgroup-parent string Optional parent cgroup for the container
--compress Compress the build context using gzip
--cpu-period int Limit the CPU CFS (Completely Fair Scheduler) period
--cpu-quota int Limit the CPU CFS (Completely Fair Scheduler) quota
-c, --cpu-shares int CPU shares (relative weight)
--cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
--disable-content-trust Skip image verification (default true)
-f, --file string Name of the Dockerfile (Default is 'PATH/Dockerfile')
--force-rm Always remove intermediate containers
--iidfile string Write the image ID to the file
--isolation string Container isolation technology
--label list Set metadata for an image
-m, --memory bytes Memory limit
--memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--network string Set the networking mode for the RUN instructions during build (default "default")
--no-cache Do not use cache when building the image
--pull Always attempt to pull a newer version of the image
-q, --quiet Suppress the build output and print image ID on success
--rm Remove intermediate containers after a successful build (default true)
--security-opt strings Security options
--shm-size bytes Size of /dev/shm
-t, --tag list Name and optionally a tag in the 'name:tag' format
--target string Set the target build stage to build.
--ulimit ulimit Ulimit options (default [])
```
- 依附容器的 docker attach 命令
- 構建鏡像的 docker build 命令
- 提交容器的 docker commit 命令
- 復制文件到宿主機的 docker cp 命令
- 創建容器的 docker create 命令
- 查看容器變化的 docker diff 命令
- 查看事件的 docker events 命令
- 進入容器的 docker exec 命令
- 導出容器的 docker export 命令
- 查看鏡像歷史的 docker history 命令
- 查看本地鏡像的 docker images 命令
- 導入容器的 docker import 命令
- 查看 docker 信息的 docker info 命令
- 查看各項詳細信息的 docker inspect 命令
- 殺死容器的 docker kill 命令
- 導入鏡像的 docker load 命令