How to copy files from host to Docker container?

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

    Typically there are three types:

    1. From a container to the host

      docker cp container_id:./bar/foo.txt .
      

    1. From the host to a container

      docker exec -i container_id sh -c 'cat > ./bar/foo.txt' < ./foo.txt
      

    1. From a container to a container mixes 1 and 2

      docker cp container_id1:./bar/foo.txt .
      
      docker exec -i container_id2 sh -c 'cat > ./bar/foo.txt' < ./foo.txt
      

提交回复
热议问题