[英]How do I build a dockerfile if the name of the dockerfile isn't Dockerfile?
我能夠像這樣構建 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
我們用它構建
docker build -t deepak/app Dockerfile.app
然后我得到錯誤
Uploading context 0 bytes
Error build: EOF
EOF
注意有一個點.
在兩個命令的末尾。
docker build -f MyDockerfile 。
或者用一個標簽:
docker build -t mysuperimage -f MyDockerfile 。
docker build 的最后一個參數是構建路徑,當你把.
這意味着這是您將找到Dockerfile
的路徑。 當您將其更改為Dockerfile.app
,它將嘗試查找Dockerfile.app/Dockerfile
,這是不正確的。
我不確定它是否仍然有效,但你曾經能夠做到這一點。
$ docker build -t deepak/app - < Dockerfile.app
嘗試一下,看看它是否有幫助,如果沒有,也許可以打開一個 docker 問題來重新添加此功能,或者更新有關如何使用具有不同名稱的 Dockerfile 的文檔。
更多信息: http : //docs.docker.io/en/latest/commandline/command/build/
嘗試dockerfeed 。 它使用 docker 特性通過 stdin 構建上下文。 我寫了這個腳本來解決我自己面臨的問題。
要將 Dockerfile 替換為不同的文件,您可以這樣做:
dockerfeed -d Dockerfile.app . | docker build -t deepak/ruby -
瞧。 Dockerfeed 的作用與 docker docker build
相同。 它將源代碼與其 Dockerfile 打包在一起,但允許您用所需的 Dockerfile 替換舊的 Dockerfile。 在此過程中不會創建文件,也不會更改源。 生成的 tar 存檔通過管道傳輸到 docker,然后將其發送到 docker 守護進程。
更新:在過去沒有-f
開關可用時,這是一個有效的答案。 在 docker 1.5 版中引入了這個選項。 現在您可以構建提供一個不同的 Dockerfile,如下所示:
docker build -f other-Dockerfile .
您也可以使用 docker-compose 來實現這一點。
在構建部分下的 docker-compose.yml 中,您可以指定存儲 dockerfile 的目錄及其備用名稱,如下所示:
build:
context: "/path/to/docker/directory"
dockerfile: "dockerfile-alternate-name"
這應該有效,
docker build -t <tag-name> -f <file-name> .
Windows 用戶應該嘗試以下命令:
docker build -f absolute_docker_file_path 點
例如:
docker build -f D:\\Code\\core-api\\API_TEST.Dockerfile 。
我的案例在/tmp
目錄中,並且有很多文件和 docker 嘗試使用其他文件,盡管我通過了-f <Dockerfile.foo>
最干凈、最簡單(對我來說)的解決方案是( dockerfeed
上面答案中的dockerfeed
):
cat DockerFile.debian.foo | docker build -t debian.foo -
如果您有多個Dockerfile
,就像在大型項目中的情況一樣,您可以指定要使用的相應的完全限定的Dockerfile
。
docker build -t swagger_local -f /Users/123456/myrepos/storage/services/gateway/swagger/Dockerfile .
從/Users/123456/myrepos/storage
運行的命令使用Dockerfile
中的Dockerfile
創建一個swagger_local
圖像(在我的情況下是services/gateway
)
假設您已成功安裝 docker 工具箱,包括docker-compose和docker-machine 。 這是我的 docker-compose.yml
version: '2'
services:
web: ./www/python
ports:
- "5000:5000"
這是在 Dockerfile 下
FROM python:3.4-alpine
ADD ./www/python /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
確保這些文件正好位於根文件夾下。 當您運行 docker-compose up 時,您將為 Web 構建鏡像。
對我來說,一旦我將整個路徑放在文件選項中,它就起作用了:
(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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.