【问题标题】:How would I update node.js inside of Docker container on Windows如何在 Windows 上更新 Docker 容器内的 node.js
【发布时间】:2022-01-19 12:25:38
【问题描述】:

我在寻找关于如何更新和检查在我的 Docker 容器上运行的 Node 版本的好文档时遇到了问题。这只是 .net 2 应用程序的常规容器。提前谢谢你。

【问题讨论】:

    标签: node.js docker


    【解决方案1】:

    直接回答您的问题:

    如果您没有拥有图片的Dockerfile

    1. 您可能(!)通过将 shell 放入容器然后运行 ​​node --versionnpm --version 来确定容器中 NodeJS 的版本。你可以试试docker run .... --entrypoint=bash your-container node --version
    2. 您可以更改正在运行的 Container,然后使用 docker commit 从结果中创建新的 Container Image。

    如果你有图片的Dockerfile:

    1. 您应该能够查看它以确定它安装的 NodeJS 版本。
    2. 您可以在Dockerfile 中更新 NodeJS 版本并重建 Image。

    直接更新图像和容器被认为是不好的做法(即不更新Dockerfile)。

    Dockerfiles 用于创建镜像,镜像用于创建容器。首选方法是更新 Dockerfile 来更新 Image,并使用更新后的 Image 创建更新 Container。

    主要原因是为了确保可重复性并提供某种形式的审计,以便能够从更改的 Dockerfile 中推断出更改。

    【讨论】:

      【解决方案2】:

      在你的 Dockerfile 中

      FROM node:14-alpine as development

      【讨论】:

        猜你喜欢
        • 2016-01-31
        • 2019-12-15
        • 2020-01-21
        • 1970-01-01
        • 2023-02-13
        • 2017-06-30
        • 2021-11-09
        • 2021-06-07
        • 2018-01-04
        相关资源
        最近更新 更多