两个容器之间共享的卷“忙碌或锁定”

wheresmycookie

我有一个运行两个容器的部署。其中一个容器尝试构建(在部署期间)另一个容器nginx尝试提供服务的javascript捆绑包。

我想在构建后使用共享卷放置javascript捆绑包。

到目前为止,我具有以下部署文件(已删除无关的部分):

apiVersion: apps/v1
kind: Deployment
metadata:
  ...
spec:
  ...
  template:
    ...
    spec:
      hostNetwork: true
      containers:
      - name: personal-site
        image: wheresmycookie/personal-site:3.1
        volumeMounts:
        - name: build-volume
          mountPath: /var/app/dist
      - name: nginx-server
        image: nginx:1.19.0
        volumeMounts:
        - name: build-volume
          mountPath: /var/app/dist
      volumes:
      - name: build-volume
        emptyDir: {}

我已尽力遵循以下指南:

需要指出的另一件事是,我正在尝试使用本地运行此atm minikube

编辑:我用来构建此映像的Dockerfile是:

FROM node:alpine
WORKDIR /var/app

COPY . .
RUN npm install
RUN npm install -g @vue/cli@latest

CMD ["npm", "run", "build"]

我意识到在实际运行映像时不需要构建它,但是我的下一个目标是将pod实例信息作为环境变量插入,因此不幸的是,使用javascript我只能在该信息对我可用时进行构建。

问题

personal-site容器中的日志显示:

-  Building for production...
 ERROR  Error: EBUSY: resource busy or locked, rmdir '/var/app/dist'
 Error: EBUSY: resource busy or locked, rmdir '/var/app/dist'

我不确定为什么要尝试删除该版本/dist,但是还感觉这无关紧要。我可能是错的?

我认为这可能与容器/卷的生命周期有关,但是文档建议“当将Pod分配给节点时,首先创建一个emptyDir卷,并且只要该Pod在该节点上运行,它就会存在” 。

容器已经运行后,可能无法使用卷的原因有哪些?鉴于您可能比我在Kubernetes上拥有更多的经验,接下来您会考虑什么?

阿登努尔·图米

最好的方法是如下自定义图像的入口点:

  • 一旦您完成建设/var/app/dist文件夹,复制(或移动)这个文件夹到另一个空路径(.eg: /opt/dist

    cp -r /var/app/dist/* /opt/dist
    

注意:此步骤必须在ENTRYPOINT的脚本中完成,而不是在RUN层中。

  • 现在/opt/dist改用..:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      ...
    spec:
      ...
      template:
        ...
        spec:
          hostNetwork: true
          containers:
          - name: personal-site
            image: wheresmycookie/personal-site:3.1
            volumeMounts:
            - name: build-volume
              mountPath: /opt/dist # <--- make it consistent with image's entrypoint algorithm
          - name: nginx-server
            image: nginx:1.19.0
            volumeMounts:
            - name: build-volume
              mountPath: /var/app/dist
    
          volumes:
          - name: build-volume
            emptyDir: {}
    

祝好运!

如果不清楚如何自定义入口点,请与我们分享图像的入口点,我们将予以实现。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章