Mounting a host file to container in docker python

35 views Asked by At

I am looking to map a command that runs in docker to docker python. Can someone help me with the same?

sudo docker run \
  -v /home/config/host_config.xml:/opt/confd/etc/confd/init/host_init.xml \
  --rm \
  -it \
  --privileged \
  --name container1 \
  host_config

I tried mapping with volumes option in container as follows:

container = client.api.create_container(
  'host_config',
  'ls',
  name='container1',
  volumes=['/home/config/host_config.xml'],
  host_config=client.api.create_host_config(
    binds=['/home/config/host_config.xml:/opt/confd/etc/confd/init/host_init.xml']))

But I see the container creating is successful without any error but when I list using docker ps -a, it shows status as Exited.

0

There are 0 answers