How to copy files from host to Docker container?

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

    1. Get container name or short container id:

      $ docker ps
      
    2. Get full container id:

      $ docker inspect -f   '{{.Id}}'  SHORT_CONTAINER_ID-or-CONTAINER_NAME
      
    3. Copy file:

      $ sudo cp path-file-host /var/lib/docker/aufs/mnt/FULL_CONTAINER_ID/PATH-NEW-FILE
      

    EXAMPLE:

    $ docker ps
    
    CONTAINER ID      IMAGE    COMMAND       CREATED      STATUS       PORTS        NAMES
    
    d8e703d7e303   solidleon/ssh:latest      /usr/sbin/sshd -D                      cranky_pare
    
    $ docker inspect -f   '{{.Id}}' cranky_pare
    

    or

    $ docker inspect -f   '{{.Id}}' d8e703d7e303
    
    d8e703d7e3039a6df6d01bd7fb58d1882e592a85059eb16c4b83cf91847f88e5
    
    $ sudo cp file.txt /var/lib/docker/aufs/mnt/**d8e703d7e3039a6df6d01bd7fb58d1882e592a85059eb16c4b83cf91847f88e5**/root/file.txt
    

提交回复
热议问题