<tfoot id='uf0Gv'></tfoot>
  • <legend id='uf0Gv'><style id='uf0Gv'><dir id='uf0Gv'><q id='uf0Gv'></q></dir></style></legend>
  • <i id='uf0Gv'><tr id='uf0Gv'><dt id='uf0Gv'><q id='uf0Gv'><span id='uf0Gv'><b id='uf0Gv'><form id='uf0Gv'><ins id='uf0Gv'></ins><ul id='uf0Gv'></ul><sub id='uf0Gv'></sub></form><legend id='uf0Gv'></legend><bdo id='uf0Gv'><pre id='uf0Gv'><center id='uf0Gv'></center></pre></bdo></b><th id='uf0Gv'></th></span></q></dt></tr></i><div id='uf0Gv'><tfoot id='uf0Gv'></tfoot><dl id='uf0Gv'><fieldset id='uf0Gv'></fieldset></dl></div>
      <bdo id='uf0Gv'></bdo><ul id='uf0Gv'></ul>

      <small id='uf0Gv'></small><noframes id='uf0Gv'>

      1. 确定 docker 映像的操作系统分布

        时间:2023-09-10

            <tbody id='B0AsT'></tbody>

          <small id='B0AsT'></small><noframes id='B0AsT'>

              <tfoot id='B0AsT'></tfoot>
                <bdo id='B0AsT'></bdo><ul id='B0AsT'></ul>
                <i id='B0AsT'><tr id='B0AsT'><dt id='B0AsT'><q id='B0AsT'><span id='B0AsT'><b id='B0AsT'><form id='B0AsT'><ins id='B0AsT'></ins><ul id='B0AsT'></ul><sub id='B0AsT'></sub></form><legend id='B0AsT'></legend><bdo id='B0AsT'><pre id='B0AsT'><center id='B0AsT'></center></pre></bdo></b><th id='B0AsT'></th></span></q></dt></tr></i><div id='B0AsT'><tfoot id='B0AsT'></tfoot><dl id='B0AsT'><fieldset id='B0AsT'></fieldset></dl></div>
              • <legend id='B0AsT'><style id='B0AsT'><dir id='B0AsT'><q id='B0AsT'></q></dir></style></legend>

                  本文介绍了确定 docker 映像的操作系统分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我需要确定任何 docker 映像的操作系统分发名称.我可以将ubuntu:latest标记为image1:latest,但是应该可以在image1:latest启动的时候得到它的分布信息.

                  I need to determine the OS distribution name for any docker image. I can tag ubuntu:latest as image1:latest, but I should be able to get the distribution information of image1:latest when it is launched.

                  为了实现这一点,我使用下面提到的命令来确定操作系统版本:

                  For achieving this, I used the below mentioned command to determine the OS version:

                  $ docker tag ubuntu image1
                  $
                  $ docker run -it image1 /bin/sh -c "echo import platform > test.py; echo print(platform.dist()) >> test.py; python3 test.py"
                  ('Ubuntu', '14.04', 'trusty')
                  $
                  

                  但是,这取决于图像中是否包含 python2python3.ubuntu:12.04 失败,我需要在那里使用 python2.

                  However, this has a dependency on whether the image has python2 or python3 in it. It fails for ubuntu:12.04 and I need to use python2 there.

                  $ docker run -it ubuntu /bin/sh -c "echo import platform > test.py; echo print(platform.dist()) >> test.py; python3 test.py"
                  ('Ubuntu', '14.04', 'trusty')
                  $
                  $ docker run -it ubuntu:12.04 /bin/sh -c "echo import platform > test.py; echo print(platform.dist()) >> test.py; python3 test.py"
                  /bin/sh: 1: python3: not found
                  $
                  $ docker run -it ubuntu:12.04 /bin/sh -c "echo import platform > test.py; echo print(platform.dist()) >> test.py; python2 test.py"
                  ('Ubuntu', '12.04', 'precise')
                  $ 
                  

                  第一季度.有没有一种方法可以在不知道特定图像中存在哪个版本的 python 的情况下实现相同的目标?

                  Q1. Is there a way I can achieve the same without knowing which version of python is there in a particular image?

                  注意:目标是确定用于构建此映像的基础映像.我无权访问用于构建此映像的 Dockerfile.

                  NOTE: The goal is to determine which was the base image used to build this image. I don't have access to the Dockerfile used to build this image.

                  第二季度.还有另一种使用入口点的方法.我可以使用 Dockerfile 从当前图像构建一个单独的图像.或者,我可以在创建容器时在 cmdline 中指定入口点,但我需要在容器内可以访问脚本.我猜我在使用 cmdline 时可能需要共享存储,有没有更好的方法来实现这一点?任何指针都会很有帮助.

                  Q2. There is another approach of using entrypoint. I can build a separate image from the current image using Dockerfile. Or, I can specify entrypoint in cmdline when creating container but I need the script to be accessible within the container. I am guessing that I might need shared storage when using cmdline, is there a better way to achieve this? Any pointers would be really helpful.

                  谢谢.

                  推荐答案

                  文件系统层次标准有一个 /etc/os-release 的标准定义,应该在大多数发行版上都可用:

                  The Filesystem Hierarchy Standard has a standard definition for /etc/os-release, which should be available on most distributions:

                  /etc/os-release 和/usr/lib/os-release 文件包含操作系统标识数据.

                  The /etc/os-release and /usr/lib/os-release files contain operating system identification data.

                  os-release 的基本文件格式是换行符分隔的类似环境的 shell 兼容变量赋值列表.可以从 shell 脚本中获取配置.

                  The basic file format of os-release is a newline-separated list of environment-like shell-compatible variable assignments. It is possible to source the configuration from shell scripts.

                  这意味着您可以只获取 /etc/os-release 并使用 $NAME$ID 来识别发行版.例如,在 Fedora 上它看起来像这样:

                  This means you can just source /etc/os-release and use $NAME or $ID to identify the distribution. As an example, on Fedora it looks like this:

                  % source /etc/os-release
                  % echo $NAME
                  Fedora
                  % echo $ID
                  fedora
                  

                  在 Debian 上:

                  On Debian:

                  % source /etc/os-release
                  % echo $NAME
                  Debian GNU/Linux
                  % echo $ID
                  debian
                  

                  这篇关于确定 docker 映像的操作系统分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:“找不到 jpeg 的头文件或库文件"在 Alpine Li 下一篇:/var/run/docker.sock:在 Python CGI 脚本中运行 docker 时权

                  相关文章

                  最新文章

                  <tfoot id='Mnhut'></tfoot>
                    <bdo id='Mnhut'></bdo><ul id='Mnhut'></ul>
                  1. <i id='Mnhut'><tr id='Mnhut'><dt id='Mnhut'><q id='Mnhut'><span id='Mnhut'><b id='Mnhut'><form id='Mnhut'><ins id='Mnhut'></ins><ul id='Mnhut'></ul><sub id='Mnhut'></sub></form><legend id='Mnhut'></legend><bdo id='Mnhut'><pre id='Mnhut'><center id='Mnhut'></center></pre></bdo></b><th id='Mnhut'></th></span></q></dt></tr></i><div id='Mnhut'><tfoot id='Mnhut'></tfoot><dl id='Mnhut'><fieldset id='Mnhut'></fieldset></dl></div>

                    <small id='Mnhut'></small><noframes id='Mnhut'>

                    1. <legend id='Mnhut'><style id='Mnhut'><dir id='Mnhut'><q id='Mnhut'></q></dir></style></legend>