docker - 如何通过 yaml list 挂载 docker 容器的卷?

标签 docker google-cloud-platform google-kubernetes-engine

我尝试使用以下 yaml 启动容器虚拟机:

version: v1
kind: Pod
spec:
  containers:
    - name: simple-echo
      image: gcr.io/google_containers/busybox
      command: ['nc', '-p', '8080', '-l', '-l', '-e', 'echo', 'hello world!']
      imagePullPolicy: Always
      ports:
        - containerPort: 8080
          hostPort: 8080
          protocol: TCP
      volumeMounts:
        - name: string
          mountPath: /home
          readOnly: false
  restartPolicy: Always
  dnsPolicy: Default
  volumes:
    - name: string
      source:
        # Either emptyDir for an empty directory
        # emptyDir: {}
        # Or hostDir for a pre-existing directory on the host
        hostDir:
          path: /home

我希望可以从容器访问主机主目录。

但是,容器无法启动:

E0619 05:02:09.477574    2212 http.go:54] Failed to read URL: invalid pod: 
[spec.volumes[0].source: invalid value '<*>(0xc2080b79e0){HostPath:<nil> EmptyDir:<nil> GCEPersistentDisk:<nil> AWSElasticBlockStore:<nil> 
GitRepo:<nil> Secret:<nil> NFS:<nil> ISCSI:<nil> Glusterfs:<nil> PersistentVolumeClaimVolumeSource:<nil> RBD:<nil>}': 
exactly 1 volume type is required spec.containers[0].volumeMounts[0].name: not found 'string']

指定容器卷的正确方法是什么?

最佳答案

尝试将 hostDir 替换为 hostPath,如 v1beta3-conversion-tips-from-v1beta12 中所述。 。

尝试更换

volumes:
    - name: string
      source:
        # Either emptyDir for an empty directory
        # emptyDir: {}
        # Or hostDir for a pre-existing directory on the host
        hostDir:
          path: /home

volumes:
    - name: string
      hostPath:
        path: /home

位于配置的底部。

关于docker - 如何通过 yaml list 挂载 docker 容器的卷?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30930351/

相关文章:

kubernetes - 如何检查网络策略是否已应用于Pod?

docker - 如何通过命令行指定在docker-compose中使用哪个env_file

ubuntu - ubuntu 18.04 中的 Docker 交换支持

firebase - 如何为 firebase 创建服务帐户以与 firebase 功能一起使用

google-cloud-platform - 如何使用 terraform 停止 GCP vm 实例

google-cloud-platform - 将文件上传到 Google Persistent Disk

spring-boot - 如何访问Google Kubernetes中部署的多个服务(Spring boot应用程序)?

oracle - 如何强制 flyway 清理我的 docker oracle 数据库?

docker - docker stack deploy带有工作目录的Windows卷路径

docker - 使用 kubernetes 时找不到 Package.json 文件