How to Copy file to stopped docker container

前端 未结 4 2098
孤独总比滥情好
孤独总比滥情好 2021-02-18 21:04

I am running elasticsearch from within a docker container.

While configuring elasticsearch for ssl and shield my elasticsearch.yml file got illegal entry i

4条回答
  •  -上瘾入骨i
    2021-02-18 21:14

    There are several cases:

    1. In the container, the elasticsearch.yml file resides in a volume data directory

    Volume data directory is a special data storage backend for Docker containers, which is called vfs backend. The directories are essentially normal directories mapped in the host file system, thus provide no copy-on-write capability. Mainly the mapped directories locate at /var/lib/dockers/vfs/dir/{container_id}, but this is configurable. To be sure, you can use docker inspect {container_name} to check the location:

    $> docker inspect my_container
    
    ..... (omitted output)
    
    "Volumes": {
    "/datadir": "/var/lib/docker/vfs/dir/b2479214c25cd39c901c3211ed14cb9668eef822a125ca85de81425d53c9ccee"
    },
    

    As you can see, /datadir, which is a volume data directory in the container, is mapped to /var/lib/docker/vfs/dir/b2479214c25cd39c901c3211ed14cb9668eef822a125ca85de81425d53c9ccee of the host file system. Under such circumstances, the answer to your question is quite easy: just copy them as normal files into the mapped host directory.

    1. The directory in container is not volume data directory.

    Since Docker can use multiple storage backend for non-volume directories, there is no simple answer for you question.

    If you happened to use AUFS as the backend, the container file system is mounted onto the host file system, which is somehow similar to the vfs case. You can locate the mapped directory in the host file system, and access files there. For detailed information about AUFS in Docker, please refer to Docker and AUFS in practice.

    If you use other backends, e.g. devicemapper, or btrfs, I guess there's no simple way to access container files from the host. Maybe you can try @VonC 's method.

提交回复
热议问题