You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于Docker build命令中'-'的作用及Linux下含义的技术咨询

Understanding the - in docker build - < Dockerfile

Great question! Let's break down what this - does, both in the context of Docker and as a general Linux convention.

1. What - means in docker build

When you run docker build - < Dockerfile, the - tells Docker to read the build context from standard input (stdin).

Normally, docker build expects a directory path as its argument (like docker build .), which becomes the build context — all files in that directory get sent to the Docker daemon to use during the build (think of COPY or ADD commands that pull files from the context). But with -, instead of sending a full directory, Docker reads the context directly from stdin.

In your specific command, the < Dockerfile redirects the contents of your Dockerfile into stdin. So Docker uses that input as the Dockerfile itself, and since there are no other files in the context, any COPY or ADD instructions in your Dockerfile will fail (there's nothing to copy from the context). This is handy when you want to build an image without sending an entire directory, or when generating a Dockerfile dynamically and passing it straight to docker build.

2. General meaning of - in Linux commands

Across most Linux tools, - is a widely adopted convention that represents standard input (stdin) or standard output (stdout), depending on what the command is designed to do:

  • For commands that read input: - means "read from stdin instead of a file". Examples:
    • cat - will read text you type in the terminal and print it back out.
    • grep "pattern" - will search for "pattern" in input piped into stdin.
  • For commands that write output: - means "write to stdout instead of a file". Examples:
    • curl https://example.com -o - will print the downloaded content to your terminal instead of saving it to a file.
    • tar -czf - ./my-folder creates a compressed tar archive and sends it to stdout (you can pipe this to ssh user@host "tar -xzf -" to copy files over SSH directly).

There's a less common use case too: some commands use - to signal the end of command-line options, so any arguments after - are treated as filenames even if they start with -. For example, rm -- -my-file lets you delete a file named -my-file without rm interpreting it as an option.

内容的提问来源于stack exchange,提问作者pythonic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:33:14