【问题标题】:Share folder content between two containers in same pod在同一个 pod 中的两个容器之间共享文件夹内容
【发布时间】:2017-11-13 17:33:44
【问题描述】:
我有一个带有两个容器的 Pod,Nginx 和 Rails。我想将公共文件夹从 rails 共享到 nginx 容器,但是公共文件夹已经包含文件,我不希望该文件夹为空。
有没有办法使用共享卷?
我试过了:
- name: rails-assets
hostPath:
path: /app/public
但是我得到了这个错误:
Error: failed to start container "nginx": Error response from daemon: {"message":"error while creating mount source path '/app/public': mkdir /app: read-only file system"}
Error syncing pod
Back-off restarting failed container
谢谢,
【问题讨论】:
标签:
ruby-on-rails
nginx
kubernetes
google-kubernetes-engine
【解决方案1】:
我解决了在 rails 应用程序上创建共享卷 shared-assets/ 的问题。在 Rails dockerfile 上,我使用 bash 脚本创建了一个 ENTRYPOINT,以复制 shared-assets/ 文件夹中的 public/ 文件。有了这个,我现在可以看到 Nginx 容器上的文件了。
---
kind: Deployment
apiVersion: apps/v1beta1
metadata:
name: staging-deployment
spec:
replicas: 1
revisionHistoryLimit: 2
template:
metadata:
labels:
app: staging
spec:
containers:
- name: staging
image: some/container:v5
volumeMounts:
- mountPath: /var/run/
name: rails-socket
- mountPath: /app/shared-assets
name: rails-assets
- name: nginx
image: some/nginx:latest
volumeMounts:
- mountPath: /var/run/
name: rails-socket
- mountPath: /app
name: rails-assets
imagePullSecrets:
- name: app-backend-secret
volumes:
- name: rails-socket
emptyDir: {}
- name: rails-assets
emptyDir: {}
还有脚本ENTRYPOINT:
cp -r /app/public/ /app/shared-assets/