Running copy command in docker python can't handle asterisk

287 views Asked by At

I am trying to run a docker container to copy files from a volume to a local folder:

import docker
client = docker.from_env()
stdout = client.containers.run(
    "alpine",
    mounts=[
        docker.types.Mount(
            "/data_to",
            os.path.abspath("./data_localhost"),
            'bind')
    ],
    volumes={
        volume_name: {'bind': '/data_from', 'mode': 'rw'}
    },
    working_dir='/data_from',
    command=["cp", "/data_from/*", "/data_to/"]
    # command=["touch", "/data_to/a"]
    # command=["ls", "/data_from/"]
)
logging.info(stdout.decode("utf-8"))

But I get

docker.errors.ContainerError: Command '['cp', '/data_from/*', '/data_to/']' in image 'alpine' returned non-zero exit status 1: b"cp: can't stat '/data_from/*': No such file or directory\n"

It seems to not handle the asterisk correctly. Why is this?

I can ls the content of /data_from/ correctly and also write data to /data_to/ from within the container.

0

There are 0 answers