are VOLUME in Dockerfile persistent in kubernetes

后端 未结 1 805
闹比i
闹比i 2021-01-29 04:45

Some Dockerfile have a VOLUME command.

What happens when such containers are deployed in Kubernetes, but no kubernetes volume are provided: no persistent volume (PV), nor

相关标签:
1条回答
  • 2021-01-29 05:37

    (answer based on what I observed with Rancher 2.4, kubernetes 1.17 using Docker)

    Short answer:

    a Docker volume is created in /var/lib/docker/volumes/... and removed when the pods is stopped or redeployed.

    Long answer:

    Kubernetes doesn't seems to have any knowledge of the volume the containers / in the Dockerfile. No Kubernetes objects seems to be created.

    When Kubernetes tell Docker daemon to start a container, Docker creates a volume (like docker volume create) and attach the created volume (unless kubernete's provides a volume to mount).

    Where are the file stored ?

    The file is a regular Docker volume (see docker volume below)

    Is the volume persistent ?

    No, the docker volume is removed when the pod is removed (like if you ran docker rm $mycontainer --volumes)


        docker inspect 6ce5f52186d4 | grep '"Driver": "local"' -A5 -B5
    
                {
                    "Type": "volume",
                    "Name": "679135a23430ceea6adb8d89e04c6baf9da33239a83ecb4c4ec3263e2c925d39",
                    "Source": "/var/lib/docker/volumes/679135a23430ceea6adb8d89e04c6baf9da33239a83ecb4c4ec3263e2c925d39/_data",
                    "Destination": "/var/lib/postgresql/data",
                    "Driver": "local",
                    "Mode": "",
                    "RW": true,
                    "Propagation": ""
                }
    
     $ docker volume ls
    DRIVER              VOLUME NAME
    local               679135a23430ceea6adb8d89e04c6baf9da33239a83ecb4c4ec3263e2c925d39
    
     $ du -hs /var/lib/docker/volumes/679135a23430ceea6adb8d89e04c6baf9da33239a83ecb4c4ec3263e2c925d39/
    51.4M   /var/lib/docker/volumes/679135a23430ceea6adb8d89e04c6baf9da33239a83ecb4c4ec3263e2c925d39/
    
    0 讨论(0)
提交回复
热议问题