How to copy files from host to Docker container?

前端 未结 30 2960
南方客
南方客 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:25

    The cp command can be used to copy files.

    One specific file can be copied TO the container like:

    docker cp foo.txt mycontainer:/foo.txt
    

    One specific file can be copied FROM the container like:

    docker cp mycontainer:/foo.txt foo.txt
    

    For emphasis, mycontainer is a container ID, not an image ID.

    Multiple files contained by the folder src can be copied into the target folder using:

    docker cp src/. mycontainer:/target
    docker cp mycontainer:/src/. target
    

    Reference: Docker CLI docs for cp

    In Docker versions prior to 1.8 it was only possible to copy files from a container to the host. Not from the host to a container.

提交回复
热议问题