小编Mar*_*uri的帖子

Docker SDK for Python:如何使用自定义 Dockerfile 和自定义上下文构建映像

我正在尝试使用 Docker SDK for Python 复制此命令:

\n
docker build -f path/to/dockerfile/Dockerfile.name -t image:version path/to/context/.\n
Run Code Online (Sandbox Code Playgroud)\n

path/to/dockerfilepath/to/context是不同的路径,即:\n /opt/project/dockerfile/opt/project/src/app/。

\n

目录结构如下:

\n
opt\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 project\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dockerfile\n\xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Dockerfile.name\n\xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82       \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 app\n\xe2\x94\x82           \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 target\n\xe2\x94\x82               \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 app-0.0.1-SNAPSHOT.jar\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 script.py\n
Run Code Online (Sandbox Code Playgroud)\n

该命令在 CLI 中可以正常工作,但我无法使其与 SDK 一起工作。

\n

文档来看,图像构建方法具有以下参数:

\n
    \n
  • path (str) \xe2\x80\x93 包含 Dockerfile 的目录的路径(我猜这是上下文)
  • \n
  • custom_context (bool) \xe2\x80\x93 如果使用 fileobj 则可选
  • \n
  • fileobj \xe2\x80\x93 用作 Dockerfile 的文件对象。(或类似文件的对象)
  • \n
\n

当我使用这样的方法时:

\n
client.images.build(\n    path = …
Run Code Online (Sandbox Code Playgroud)

python docker dockerfile

5
推荐指数
1
解决办法
2970
查看次数

标签 统计

docker ×1

dockerfile ×1

python ×1