验证在Docker容器中运行的ubuntu的版本 [英] Verify the version of ubuntu running in a Docker container
问题描述
我在Windows 8.1上安装了Docker Toolbox,并且正在基于ubuntu:latest(应该为16.04)创建映像.我想确保我的应用程序确实在16.04上运行.这是我的Dockerfile:
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 on 16.04. Here is my Dockerfile:
FROM ubuntu:latest
MAINTAINER xyz xyz@abc.com
COPY apt.conf /etc/apt/
RUN apt-get -y update
RUN apt-get -y install cmake
RUN mkdir /usr/local/
COPY folder /usr/local/
RUN mkdir /usr/local/build
CMD cd /usr/local/build
CMD cmake /usr/local/
建立图像后,我尝试运行:
Once the image is built, i try to run :
docker run image uname -r
但是它总是以4.4.12 boot2docker
现在我知道boot2docker是轻量级的Linux VM,它是在Windows上旋转了哪些容器的顶部,但是不应该运行该映像来获取正在运行的ubuntu版本吗?我该如何验证?
Now i know that boot2docker is the lightweight linux VM on top of which containers are spun on windows, however shouldn't running the image give me version of ubuntu it's running? How can i verify this?
推荐答案
uname
命令正在从主机上运行的内核中提取规范.如果我在Debian主机上输入Ubuntu容器,则uname将以Debian构建的内核来回答.
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.
要了解您正在运行的Ubuntu版本,请执行
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"
Shell脚本友好的简单变量,因此您可以运行
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
...
这篇关于验证在Docker容器中运行的ubuntu的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!