0

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.

4
  • Gobbling probably doesn't work because command runs with sh, not bash Commented Oct 23, 2020 at 15:50
  • Also, not clear what you're trying to copy. The working of /data_from starts empty... Or are you trying to extract data from a docker volume? Commented Oct 23, 2020 at 15:54
  • yes, i am trying to get the data out of an already filled volume Commented Oct 23, 2020 at 16:15
  • Why can't you use cp -r /data_from /data_to? Or maybe even rsync? Commented Oct 23, 2020 at 16:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.