该命令用于构建镜像,与 Dockerfile 配合使用。
语法:
docker build [OPTIONS] PATH | URL | -
命令参数详细说明
-c, --cpu-shares=0 CPU shares (relative weight)
--cgroup-parent= Optional parent cgroup for the container
--cpu-period=0 Limit the CPU CFS (Completely Fair Scheduler) period
--cpu-quota=0 Limit the CPU CFS (Completely Fair Scheduler) quota
--cpuset-cpus= CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems= MEMs in which to allow execution (0-3, 0,1)
-f, --file= Name of the Dockerfile (Default is 'PATH/Dockerfile')
--force-rm=false Always remove intermediate containers
--help=false Print usage
-m, --memory= Memory limit
--memory-swap= Total memory (memory + swap), '-1' to disable swap
--no-cache=false Do not use cache when building the image
--pull=false Always attempt to pull a newer version of the image
-q, --quiet=false Suppress the verbose output generated by the containers
--rm=true Remove intermediate containers after a successful build
-t, --tag= Repository name (and optionally a tag) for the image
常用参数说明:
- -c:控制 CPU 使用
- -f:指定 Dockerfile 名称
- -m:设置构建内存上限
- -q:不显示构建过程的信息
- -t:为构建的镜像打上标签
示例
构建一个镜像,命名为 test_panguggle ,指定上下文目录为当前目录:
docker build -t "test_panguggle" .
构建一个镜像,命名为 test_panguggle ,同时指定上下文目录为 test:
docker build -t "test_panguggle" ./test/
构建一个镜像,命名为 test_panguggle ,标签为 new, 同时指定上下文目录为当前目录,文件为 test 目录内的 newfile,且不显示构建过程:
docker build -q -f test/newfile -t "test_panguggle:new" .
注意:
上面的 . 表示当前目录,也就是说,要执行build 命令,必须cd Dockerfile 所在的目录, 这点一定要注意!一定要注意!一定要注意!