Flow of the python script:
- I want to run docker image from python script.
- After running docker image, I need to execute a shell script which creates a tar file inside docker container.
- I need to copy that tar file to host machine from docker container.
- and then python script should continue with some stuff to be executed on host machine.
Using docker-py module, I was able to do following:
pip install docker-py
docker version
Client:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built: Thu Aug 18 05:22:43 2016
OS/Arch: linux/amd64
Server:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built: Thu Aug 18 05:22:43 2016
OS/Arch: linux/amd64
>>> import docker
>>> c = docker.Client(base_url='unix://var/run/docker.sock',version='1.12',timeout=10)
>>> c.images()
[{u'Created': 1476217543, u'Labels': {}, u'VirtualSize': 5712315133, u'ParentId': u'sha256:1ba2be8d70b6ede3b68b1af50759e674345236dd952225fcbfbcc1781f370252', u'RepoTags': [u'ubuntu14.04_64:latest'], u'RepoDigests': None, u'Id': u'sha256:1c8ced0fb34d776adafaed938d41a69e3bab87466beaa8752d49bde0d81230c5', u'Size': 5712315133}]
>>> ctr = c.create_container('ubuntu14.04_64:latest')
>>> c.start(ctr)
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d685766385e7 ubuntu14.04_64:latest "bash" 16 hours ago Up 16 hours focused_fermi
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu14.04_64 latest 1c8ced0fb34d 21 hours ago 5.712 GB
I see docker image and container running on host, but now if I want to run shell script inside docker container, how can I do that? after that I need to copy tar from container to host also. Can someone suggest how to do this?