Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build an Image using Docker API Python Client?

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!

like image 313
Abdul Rehman Avatar asked Jul 15 '17 07:07

Abdul Rehman


People also ask

How do I Dockerize API in Python?

You need to set up a working directory and then copy the contents from the local directory to the docker directory. Then, you need to run the install command so that it installs all the dependencies. Finally, you need to give the command when the container is instantiated.


1 Answers

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.

like image 186
sarthakgupta072 Avatar answered Oct 09 '22 03:10

sarthakgupta072