How to build an Image using Docker API Python Client?

社会主义新天地 提交于 2019-12-14 02:27:43

问题


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 ?

Help me, please! Thanks in advance!


回答1:


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() is the method to build the docker images.
Now it can have several parameters:

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>")

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

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

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.



来源:https://stackoverflow.com/questions/45115509/how-to-build-an-image-using-docker-api-python-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!