【问题标题】:Accessing container mounted volumes in Kubernetes from docker container从 docker 容器访问 Kubernetes 中的容器安装卷
【发布时间】:2019-12-18 15:33:24
【问题描述】:

我目前正在尝试从 docker 映像访问安装在我的 Kubernetes 容器中的文件。当我的 docker 镜像运行时,我需要用一个标志传递文件。

docker 镜像通常使用以下命令运行(在容器外):

docker run -p 6688:6688 -v ~/.chainlink-ropsten:/chainlink -it --env-file=.env smartcontract/chainlink local n -p /chainlink/.password -a /chainlink/.api

现在我已成功使用以下配置将我的 env、密码和 api 文件挂载到 /chainlink,但是在 docker run 期间尝试访问文件时出现错误:

flag provided but not defined: -password /chainlink/.password

以下是我当前的 Kubernetes Deployment 文件

kind: Deployment
metadata:
  name: chainlink-deployment
  labels:
    app: chainlink-node
spec:
  replicas: 1
  selector:
    matchLabels:
      app: chainlink-node
  template:
    metadata:
      labels:
        app: chainlink-node
    spec:
      containers:
        - name: chainlink
          image: smartcontract/chainlink:latest
          args: [ "local", "n", "--password /chainlink/.password", "--api /chainlink/.api"]
          ports:
          - containerPort: 6689
          volumeMounts:
            - name: config-volume
              mountPath: /chainlink/.env
              subPath: .env
            - name: api-volume
              mountPath: /chainlink/.api
              subPath: .api
            - name: password-volume
              mountPath: /chainlink/.password
              subPath: .password
      volumes:
        - name: config-volume
          configMap:
            name: node-env
        - name: api-volume
          configMap:
            name: api-env
        - name: password-volume
          configMap:
            name: password-env

我的文件中是否缺少一些定义,允许我在运行 docker 映像时访问已安装的卷?

【问题讨论】:

    标签: file docker kubernetes environment-variables volume


    【解决方案1】:

    将您的 args 更改为:

    args: [ "local", "n", "--password", "/chainlink/.password", "--api", "/chainlink/.api"]
    

    你目前拥有它的方式,它认为整个字符串--password /chainlink/.password,包括空格,是一个单一的标志。这就是错误:

    flag provided but not defined: -password /chainlink/.password
    

    告诉你。

    【讨论】:

    • 谢谢!没想到我错过了这么明显的东西。
    猜你喜欢
    • 2017-10-21
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多