Docker Community Forums

Share and learn in the Docker community.

How can i commit a container using python sdk?

#1

i would like to commit a container to create an image from this container, using python SDK

And
container = client.containers.run(name, [“touch”, “/name”], detach=True)
what is the meaning of the touch command ?

(Nitishmowall) #2

container = client.containers.run(name, [“touch”, “/name”], detach=True)

here you are running a bash command touch to create file /name.

for committing a container using python Sdk please read below link
https://docker-py.readthedocs.io/en/stable/containers.html#docker.models.containers.Container.commit

1 Like
#3

commit(repository=None)
Repositiry can be the file /name created with the touch command
commit(“name”)

(Nitishmowall) #4

repository is the image name

1 Like
#5

We specify juste the name of the commit image or should we create smoething else in the commit(…) command

(Nitishmowall) #6

you can also add tag to repository(image)

1 Like
#7

Can we use commit command to create a copy of the container by launching an a new container from the commit image?

(Nitishmowall) #8

you can create multiple images using commit( it commit the changes made in the container to image). And then can start containers using those images.
SO yes

1 Like