💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 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" . ``` ![](https://box.kancloud.cn/057be7d57b8f4f355814b7c3efcfcdfc_869x163.png) ## 帮助 ``` $ 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 []) ```