How to copy files from host to Docker container?

前端 未结 30 2495
南方客
南方客 2020-11-22 06:58

I am trying to build a backup and restore solution for the Docker containers that we work with.

I have Docker base image that I have created, ubuntu:base

30条回答
  •  醉话见心
    2020-11-22 07:36

    This is a direct answer to the question 'Copying files from host to Docker container' raised in this question in the title.

    Try docker cp. It is the easiest way to do that and works even on my Mac. Usage:

    docker cp /root/some-file.txt some-docker-container:/root
    

    This will copy the file some-file.txt in the directory /root on your host machine into the Docker container named some-docker-container into the directory /root. It is very close to the secure copy syntax. And as shown in the previous post, you can use it vice versa. I.e., you also copy files from the container to the host.

    And before you downlink this post, please enter docker cp --help. Reading the documentation can be very helpful, sometimes...

    If you don't like that way and you want data volumes in your already created and running container, then recreation is your only option today. See also How can I add a volume to an existing Docker container?.

提交回复
热议问题