docker build
命令用于构建 Docker 镜像。其基本语法为:
docker build [OPTIONS] PATH | URL | -
其中,OPTIONS
参数包括以下常用选项:
-t
:指定构建出的镜像名称和标签;-f
:指定使用的 Dockerfile 文件路径;--build-arg
:设置构建时传递给 Dockerfile 的参数;--no-cache
:不使用缓存进行构建;--rm
:构建完成后删除中间容器。
例如,如果要构建一个名为 myimage:1.0
的镜像,可以使用以下命令:
docker build -t myimage:1.0 .
其中,.
表示使用当前目录下的 Dockerfile 进行构建。如果 Dockerfile 不在当前目录下,可以使用 -f
指定其路径,例如:
docker build -t myimage:1.0 -f /path/to/Dockerfile .