【问题标题】:Determine OS type in docker在 docker 中确定操作系统类型
【发布时间】:2018-07-11 13:27:49
【问题描述】:

我想根据运行 docker 映像的操作系统类型下载 sdk。如何在 docker 脚本中编写以下伪代码

RUN variable x = getOS()
if [ "$x" = "Darwin" ]; then
     RUN wget -q http://xxx/android-ndk-xxxx-darwin-x86_64.bin
else
     RUN wget -q http://xxx/android-ndk-xxxx-linux-x86_64.bin

【问题讨论】:

  • 您想知道与所有容器共享的主机内核是操作系统,还是单个容器使用的基本映像(文件系统)是操作系统?
  • 为什么要依赖于主机操作系统类型的 Dockerfile?这违背了 Docker 的Build once, Run anywhere 目标,并且可能无法正常工作

标签: android bash amazon-web-services docker dockerfile


【解决方案1】:

使用uname 命令。

x=$(uname)

在 darwin 系统上,它应该输出Darwin

在您的 dockerfile 中,RUN 命令可能如下所示:

RUN [ "$(uname)" = Darwin ] && system=darwin || system=linux; \
    wget -q http://xxx/android-ndk-xxxx-${system}-x86_64.bin

或者这样(为了支持任意系统):

RUN system=$(uname); \
    wget -q http://xxx/android-ndk-xxxx-${system,}-x86_64.bin

【讨论】:

    猜你喜欢
    • 2011-10-20
    • 1970-01-01
    • 2013-01-02
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2016-12-11
    • 2019-04-13
    • 2015-12-10
    相关资源
    最近更新 更多