问题
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