How to mount a directory in a Docker container to the host?

后端 未结 2 1634
一生所求
一生所求 2021-02-02 12:06

Assume that i have an application with this simple Dockerfile:

//...
RUN configure.sh --logmyfiles /var/lib/myapp
ENTRYPOINT [\"starter.sh\"]
CMD [\"run\"]
EXPOS         


        
2条回答
  •  难免孤独
    2021-02-02 12:46

    So how can i mount the /var/lib/myapp from the container to the /var/lib/myapp in host server

    That is the opposite: you can mount an host folder to your container on docker run.

    (without removing current container)

    I don't think so.
    Right now, you can check docker inspect and see if you see your log in the /var/lib/docker/volumes/... associated to the volume from your container.

    Or you can redirect the result of docker logs to an host file.
    For more example, see this gist.

    The alternative would be to mount a host directory as the log folder and then access the log files directly on the host.

    me@host~$ docker run -d -p 80:80 -v :/etc/nginx/sites-enabled -v :/etc/nginx/certs -v :/var/log/nginx dockerfile/nginx
    
    me@host~$ ls  
    

    (again, that apply to a container that you start, not an existing running one)

提交回复
热议问题