Verify the version of ubuntu running in a Docker container

后端 未结 2 1204
执笔经年
执笔经年 2021-02-05 04:52

I have Docker Toolbox installed on windows 8.1 and I am creating an image based on ubuntu:latest (which should be 16.04). I want to make sure that my application is indeed run o

相关标签:
2条回答
  • 2021-02-05 05:06

    The uname command is pulling specs from the kernel running on the host. If I enter a Ubuntu container on my Debian host, the uname will answer with a Debian build of the kernel.

    To know the version of Ubuntu you are running, do a

    $ cat /etc/lsb-release
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=16.04
    DISTRIB_CODENAME=xenial
    DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"
    

    It's simple variables that are shell script friendly, so you can run

    #!/bin/sh
    
    if [ ! -f /etc/lsb-release ]; then
      echo "lsb-release missing, unlikely to be a Ubuntu system"
      exit 1
    fi
    . /etc/lsb-release
    if [ "$DISTRIB_ID" != "Ubuntu" -o "$DISTRIB_RELEASE" != "16.04" ]; then
      echo "Linux install doesn't appear to be Ubuntu 16.04"
      exit 1
    fi
    ...
    
    0 讨论(0)
  • 2021-02-05 05:10

    Try this

    cat /etc/os-release
    

    It will return like this

    NAME="Ubuntu"
    VERSION="16.04.3 LTS (Xenial Xerus)"
    ID=ubuntu
    ID_LIKE=debian
    PRETTY_NAME="Ubuntu 16.04.3 LTS"
    VERSION_ID="16.04"
    HOME_URL="http://www.ubuntu.com/"
    SUPPORT_URL="http://help.ubuntu.com/"
    BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
    VERSION_CODENAME=xenial
    UBUNTU_CODENAME=xenial
    
    0 讨论(0)
提交回复
热议问题