我能够建立一个Dockerfile像

Docker build -t deepak/ruby。

但是对于一个Dockerfile,它不叫Dockerfile

# DOCKER-VERSION 0.4.8

FROM deepak/ruby

MAINTAINER Deepak Kannan "deepak@example.com"

RUN ./bin/rails s

我们假设它叫Dockerfile.app 我们用它来建造

Dockerfile.app . docker build -t deepak/app

然后得到错误

Uploading context 0 bytes
Error build: EOF
EOF

当前回答

注意这里有个点。在两个命令的末尾。

docker build -f MyDockerfile .

或者带一个标签:

docker build -t mysuperimage -f MyDockerfile .

其他回答

这个应该可以,

Docker build -t <tag-name> -f <file-name>。

dockerfeed试试。它使用docker特性通过stdin构建上下文。我写这个剧本就是为了解决你的问题。

用一个不同的Dockerfile替换一个Dockerfile,你可以这样做:

dockerfeed -d Dockerfile.app . | docker build -t deepak/ruby -

瞧。Dockerfeed和docker build做的是一样的。它将源文件与Dockerfile打包在一起,但允许您用所需的Dockerfile替换旧的Dockerfile。在此过程中不会创建任何文件,也不会更改源。生成的tar归档文件通过管道传输到docker, docker又将其发送到docker守护进程。

更新: 在以前没有-f开关的时候,这是一个有效的答案。在docker 1.5版中引入了这个选项。现在你可以像这样构建一个不同的Dockerfile:

docker build -f other-Dockerfile .

对我来说,一旦我把整个路径放在文件选项中,它就起作用了:

(meta_learning) brandomiranda~ ❯ docker build -f ~/iit-term-synthesis/Dockerfile_arm -t brandojazz/iit-term-synthesis:test_arm ~/iit-term-synthesis/

[+] Building 43.8s (9/28)
 => [internal] load build definition from Dockerfile_arm                                                                                           0.0s
 => => transferring dockerfile: 2.59kB                                                                                                             0.0s
 => [internal] load .dockerignore                                                                                                                  0.0s
 => => transferring context: 2B                                                                                                                    0.0s
 => [internal] load metadata for docker.io/continuumio/miniconda3:latest                                                                           0.0s
 => [ 1/24] FROM docker.io/continuumio/miniconda3                                                                                                  0.0s
 => CACHED https://api.github.com/repos/IBM/pycoq/git/refs/heads/main                                                                              0.0s
 => [ 2/24] RUN apt-get update   && apt-get install -y --no-install-recommends     ssh     git     m4     libgmp-dev     opam     wget     ca-ce  14.9s
 => [ 3/24] RUN useradd -m bot                                                                                                                     0.2s
 => [ 4/24] WORKDIR /home/bot                                                                                                                      0.0s
 => [ 5/24] ADD https://api.github.com/repos/IBM/pycoq/git/refs/heads/main version.json                                                            0.0s
 => [ 6/24] RUN opam init --disable-sandboxing                                                                                                    28.6s
 => => # [ocaml-base-compiler.4.14.0] downloaded from cache at https://opam.ocaml.org/cache
 => => # <><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
 => => # ∗ installed base-bigarray.base
 => => # ∗ installed base-threads.base
 => => # ∗ installed base-unix.base
 => => # ∗ installed ocaml-options-vanilla.1

这对我来说是失败的:

(meta_learning) brandomiranda~ ❯ docker build -f Dockerfile_arm -t brandojazz/iit-term-synthesis:test_arm ~/iit-term-synthesis/
[+] Building 0.0s (1/2)
 => ERROR [internal] load build definition from Dockerfile_arm                                                                                     0.0s
 => => transferring dockerfile: 40B                                                                                                                0.0s
------
 > [internal] load build definition from Dockerfile_arm:
------
failed to solve with frontend dockerfile.v0: failed to read dockerfile: error from sender: open .Trash: operation not permitted

Windows用户应尝试以下命令:

Docker build -f absolute_docker_file_path dot

例如:

docker build -f D:\Code\core-api\API_TESTDockerfile。

这是

docker build -t doronaviguy/helloworld -f SomeDockerFile .

Docker构建文档