6

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!

2
  • 1
    Does stackoverflow.com/a/43903346/6309 help? Commented Jul 15, 2017 at 7:19
  • no, actually I want to build a docker image using zip archive which includes dockerfile and other stuff. Commented Jul 15, 2017 at 7:35

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Any way to do this in a non-blocking way?
@CGFoX maybe run it in a thread

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.