问题原文
原帖链接 · Drux · CC BY-SA 3.0
I would like to build a Docker container and then run it in GKE after mounting some directories from GCE persistent disks (PDs). For instance, I'd like for the application's (read-write) configuration files in /etc/<application>/ to live longer than its pods (which may restart at any time.)
The regular build puts default configuration files into /etc/<application>/ and it is imperative that these are somehow "copied" once from the image's ephemeral disk into the PD, such that the application can start in its expected environment.
Is there a best practice for making this happen? For instance, would I have to mount PDs also in my Dockerfile, or can I somehow request that PDs be "synced" with files from another directory/volume/disk when they are first mounted by a VM instance during deployment?
已采纳解答
原帖链接 · Drux · CC BY-SA 3.0
I did not hear about best practices, so this is what I have adopted for now:
docker buildthe image withDockerfilethat also tars e.g./etc/<application>/into<application>.tarafter it has done its other build steps- briefly
docker runthe image andscptar files off the running image - briefly create a temporary VM instance and add/attach the PD to it;
scptar files to the VM instance;gcloud compute sshinto tit, mount the PD, and untar needed files below mount point
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
