How to copy files from host to Docker container?

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

    Assuming the container is already running, type the given command:

    # cat /path/to/host/file/ | docker exec -i -t  bash -c "/bin/cat > /path/to/container/file"
    

    To share files using shared directory, run the container by typing the given command:

    # docker run -v /path/to/host/dir:/path/to/container/dir ...
    

    Note: Problems with permissions might arise as container's users are not the same as the host's users.

提交回复
热议问题