如何使用Docker API Python客户端构建映像? [英] How to build an Image using Docker API Python Client?

查看:65
本文介绍了如何使用Docker API Python客户端构建映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚启动Docker Api并探索了各个部分,但是我被困在使用python客户端使用docker api构建映像的过程中,实际上我不明白如何为docker client设置各种必需的参数.images.build()方法?

I just have started Docker Api and explored various parts.But I'm stuck to build an image using docker api by using python client, actually I couldn't understand how to setup various required arguments for docker client.images.build() method ?

请帮帮我!预先感谢!

推荐答案

根据官方文档

According to the official documentation https://docker-py.readthedocs.io/en/stable/images.html is used to build an image using docker module of python.

(这个问题是一年前提出的,但是我会写给别人参考:))

(The question was asked a year ago, but I'll write it for other people's reference :) )

对于基本的理解,您可以使用它,我将其余的部分留给您探索.

For a basic understanding, you can use this, and I will leave the rest for you to explore.

client.images.build()是构建docker镜像的方法.
现在它可以有几个参数:

client.images.build() is the method to build the docker images.
Now it can have several parameters:

类似于 path (str)–包含Dockerfile的目录的路径.
您可以像这样指定参数:

Like path (str) – Path to the directory containing the Dockerfile.
You can specify the parameter like this:

client.images.build(path =< path_to_the_Dockerfile>")

例如,如果您的Dockerfile位于当前目录中,则将编写 client.images.build(path ="./")

For example, if your Dockerfile is in the current directory you will write client.images.build(path = "./")

此命令将从您在当前目录中拥有的Dockerfile中构建所需的映像.

This command will build the required image from the Dockerfile you would have in your current directory.

您可以通过运行命令 docker image ls (如果需要,使用 sudo docker image ls )从终端检查映像是否已成功构建,并且您将在终端中,在结果顶部看到您创建的图像.

You can check from your terminal if your image has been successfully build by running the command docker image ls (use sudo docker image ls if required), and you will see the image you created at the top of the results in the terminal.

这篇关于如何使用Docker API Python客户端构建映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆