How to check what OS a docker image depends on? - docker

I want to extend my jenkins image to have docker installed so it can build a Dockerfile out of a project.
I found a nice install script for docker but only for Ubuntu 64bit. What I need to know is if the parent images of my jenkins image base on Ubuntu 64bit so I can use this install script without any problems.
I used docker image inspect <imagename> already but it only yields hashes for former image versions it seems.

docker run <image-name> cat /etc/*release*
It will return the metadata about your image. In the following form.
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
VARIANT_ID="202011171307-al2.470.0"
Amazon Linux release 2 (Karoo)
cpe:2.3:o:amazon:amazon_linux:2

In the docker world you'll encounter OSes like Alpine more or less frequently.
Hence its mostly advisable to get contents of the /etc/os-release file which will in most scenarios be present.
# Tomcat 9 running on Alpine OS
docker run -it tomcat:9-alpine cat /etc/os-release
# Tomcat 9 running Debian (buster)
docker run -it tomcat:9 cat /etc/os-release

The fact that your Jenkins is built on an Ubuntu 64 bits or a Fedora 24 or a Debian jessie should not bother you, as it should work anyway.
See
Run Different Linux OS in Docker Container?
for more explanations
and also
Docker container isolation, does it care about underlying Linux OS?
Anyway, if you want to get the FROM line of the Dockerfile used to build this image,
you can use the docker image
https://hub.docker.com/r/dduvnjak/dockerfile-from-image/
to get the
FROM UBUNTU
or
FROM DEBIAN
example from
How to check for Certain Properties in Docker Images
$ docker run -v /var/run/docker.sock:/var/run/docker.sock dduvnjak/dockerfile-from-image k3ck3c/nethogs | grep FROM
will show
FROM alpine:latest

Following command worked docker run mysql cat /etc/os-release.
Output:
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
. . .

I don't think there is currently any docker command that allows you to do that. It seems that the only way is to launch the container and run those commands: determine OS distribution of a docker image

Solution: docker run mysql cat /etc/os-release
Output:
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Related

docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]]

I saw similar treads but they are different because I am using WSL2 and docker and GPU aware docker.
I have windows 10 version 2004 (build 20161.1000)
I have installed WSL 2 and have Docker Desktop 2.3.0.3 on my Windows System running.
I have Ubuntu 18.04 LTS installed in WSL 2 too.
I have installed the NVIDIA driver
The linux version is 4.19.121-microsoft-standard.
The NVIDIA driver version is 455.41 for my Laptop GPU QUADRO M2000M.
Actually I followed all the steps described in https://ubuntu.com/blog/getting-started-with-cuda-on-ubuntu-on-wsl-2 until the step where I have to run "sudo service docker stop" in an Ubuntu terminal.
This results in a message docker: unrecognized service.
I have to restart docker desktop in WIndows 10 in order to get the deamon running.
I test then in the Ubuntu terminal : docker run hello-world ==> this runs fine
Also the command docker run -it ubuntu bash ==> runs file in the Ubuntu terminal os WSL 2.
BUT when I run :
docker run -u $(id -u):$(id -g) -it --gpus all -p 8888:8888 tensorflow/tensorflow:latest-gpu-py3-jupyter
then I get the error : docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]]
This invoves microsoft,Ubuntu,NVIDIA. I have search the support sites but could not find anything that solves my prblem.
Can anyone help me here?
There is this strange answer mentioned here and here:
sudo service docker start
sudo mkdir /sys/fs/cgroup/systemd
sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd
This worked for me on WSL (Ubuntu 20.04), so I added it to the ~/.bashrc script.
Note, the first part may need to be restarting docker!

docker build with nvidia runtime

I have a GPU application that does unit-testing during the image building stage.
With Docker 19.03, one can specify nvidia runtime with docker run --gpus all but I also need access to the gpus for docker build because I do unit-testing. How can I achieve this goal?
For older version of docker that use nvidia-docker2 it was not possible to specifiy runtime during build stage, BUT you can set the default runtime to be nvidia, and docker build works fine that way. Can I do that in Docker 19.03 that doesn't need nvidia-docker anymore? If so, how?
You need use nvidia-container-runtime as explained in docs: "It is also the only way to have GPU access during docker build".
Steps for Ubuntu:
Install nvidia-container-runtime:
sudo apt-get install nvidia-container-runtime
Edit/create the /etc/docker/daemon.json with content:
{
"runtimes": {
"nvidia": {
"path": "/usr/bin/nvidia-container-runtime",
"runtimeArgs": []
}
},
"default-runtime": "nvidia"
}
Restart docker daemon:
sudo systemctl restart docker
Build your image (now GPU available during build):
docker build -t my_image_name:latest .
A "solution" I found is to first run a base image with the host nvidia drivers mounted on it
docker run -it --rm --gpus ubuntu
And then build my app within the container manually and commit the resulting image.
This is not ideal and it would be best to have access to nvidia-smi during the build phase.

can i have docker container with cuda 8 if my host has cuda 9

I have GPU system on which CUDA 9 is installed. I need a separate environment with CUDA 8. So can I create a docker container having CUDA 8 in the same host? or the host needs to have CUDA 8 also?
Thanks.
you don't need to have CUDA 8 in your host. because docker has its own kernel.
for install CUDA 8 with docker you can copy this Docker File.
https://gitlab.com/nvidia/cuda/blob/centos6/8.0/runtime/Dockerfile
after you can run this command in the same directory as your Dockerfile :
docker build -t img-cuda8 .
after you run it by this CMD
docker run -itd my-cuda -d img-cuda8

mysqld service is not starting on docker run

I am using the below command in the dockerfile to automatically start mysql on docker run:
ENTRYPOINT service mysql start && bash
The above command is working fine in some system but not in all. I also have tried the below command but still facing the same issue.
EXPOSE 3306
CMD /etc/init.d/mysql start && \
/bin/bash
I am getting the below error in some system:
* Starting MySQL database server mysqld [fail]
So can anyone please help me solve this issue. So that my docker container can run on all type of system where docker can be installed.
First, it depends on your exact docker run command.
As commented here, you approach works with docker run -itd ...
Second, it depends on the host, which should be compatible with docker execution (ie, its kernel should be the right architecture, 64bits not 32, recent enough...)
The OP adds:
I am using docker run -it docker_image_name command to run the docker image and second system i.e. Linux corona2 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux its not working.
I have used 1.8.3 version to build my image and.
is it because of the community edition version as ce is written with 18.03.1-ce.
Then yes: make sure to use the same docker version for building and running (on both servers)

How to run interactive Centos 6 within docker

I'm unable to run an interactive session with Centos:6 in docker. Works perfectly with Centos:7
>docker -v
Docker version 18.03.0-ce, build 0520e24302
>docker pull centos:6
...
>docker run -it centos:6
[just returns to my terminal]
>docker pull centos:7
...
>docker run -it centos:7
>[root#f8c0430ed2ba /]#cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
Any idea what is going on ?
I tried with older version of docker and i pulled all new images Centos:6/6.6/6.7/6.8/6.9 and it shows the same problems. I also tried with /bin/bash or sh at the end.
Also i'm sure that it used to work more or less one year ago.
I'm using ArchLinux
It is a known issue that seems to be linked to the Spectre patch:
issue 103 says:
Running a docker run --rm -it centos:6 bash fails with exit status 139 (i.e. bash exits with SIGSEGV) on Linux kernel 4.15.9. Downgrading to 4.14.15 (which is vulnerable to Spectre V1) gets rid of the segfault.

Resources