Running docker container with ubuntu:16.04 actually runs ubuntu 18.04 - linux

I was trying to run a docker container with ubuntu:16.04 (on a ubuntu 18.04 machine) with the following command:
docker run -i -t --name ubuntu ubuntu:16.04 /bin/bash
Running this command attaches me to a container. But when I check the kernel information with uname -a, it shows that the current kernel is Ubuntu 18.04. Following is the result I get:
Linux 1ac6c3456e2a 5.3.0-40-generic #32~18.04.1-Ubuntu SMP Mon Feb 3 14:05:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
What could be the cause?

Docker uses host OS kernel, there is no custom or additional kernel inside container. All containers which run on a machine are sharing this "host" kernel.
Please read this for more detail.
So #32~18.04.1-Ubuntu SMP Mon Feb 3 14:05:59 UTC 2020 in the output of uname -a is actually the Kernel version of the host machine.
To verify that you are running Ubuntu 16:04, run cat /etc/os-release. It will provide you details about your OS.

Related

Running docker on Ubuntu 18.04.2 LTS

As announced by Microsoft blog, docker is supported on WSL2 now. I am trying to install docker on Linux Subsystem for Windows10. After following all the steps mentioned in this official documentation I am getting following error.
$docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
$ docker version
Client: Docker Engine - Community
Version: 19.03.1
API version: 1.40
Go version: go1.12.5
Git commit: 74b1e89
Built: Thu Jul 25 21:21:05 2019
OS/Arch: linux/amd64
Experimental: false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Am I missing anything here?
Docker is now supported on WSL2
Pre-requisite for running docker successfully on WSL2
Windows 10 (Build 18932 or higher). To check the OS Build version Win-Key + R, run command "winver"
You can get the Build#18932 by registering for windows insider program and then check latest windows updates on your machine
Enable WSL on your machine( Windows10 ) and then run wsl --set-default-version 2 with admin on Powershell command to always use WSL2 on your machine
Now you are ready to install Linux distro on your machine. Install Ubuntu on Windows 10 WSL using these instructions
you need to start the docker explicitly with sudo /etc/init.d/docker start
To verify everything is fine after installation; run the following command on Powershell. If it shows below output, that means Ubuntu-18.04 is running on WSL 2
PS> wsl -l -v
NAME STATE VERSION
* Ubuntu-18.04 Running 2
-reference: microsoft/wsl on Github
You cant run the docker daemon inside of WSL, which means you cant host containers inside of WSL. But you can connect to the daemon running on windows using the docker client running inside of WSL.
Firstly you need to get docker desktop for windows https://docs.docker.com/docker-for-windows/install/
When you have done this do ensure that the setting to expose daemon on tcp://localhost:2375 without TLS is turned on.
Then install docker in WSL
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce
And set the env variable so that all docker commands go to the daemon exposed in windows
export DOCKER_HOST=tcp://localhost:2375
You can now enjoy your docker commands in WSL :-)
There are several tweaks and steps you still need to do to get wsl2 working with docker,
Have a look at https://codingfullstack.com/cloud/docker-installation-wsl2/ if you would like to know more about on how to get this working.

Run linux/arm container via qemu binfmt_misc on Docker LCOW

I release ARM binaries of my software, by running the compiler toolchain on an emulated ARM machine.
Linux can run foreign binaries by registering qemu-user-static in /proc/sys/fs/binfmt_misc/. This allows you to run an ARM32 or ARM64 Docker image on an x86_64 Docker host, as follows:
Preparation:
# Apply `binfmt_misc` changes on host OS
docker run --rm --privileged multiarch/qemu-user-static:register --reset
Dockerfile:
# Get x86_64 qemu-user-static binaries
FROM debian:buster
RUN apt-get update && apt-get install -qqy qemu-user-static
# Get cross-arch rootfs
FROM arm64v8/golang:latest
COPY --from=0 /usr/bin/qemu-aarch64-static /usr/bin/qemu-aarch64-static
This works great on Docker for Linux.
It also works great on Docker for Windows when using Linux Containers (MobyLinuxVM)
It doesn't work when using Docker for Windows when using Windows Containers (LCOW / hcsdiag mode). I want to use this mode because it can run both Linux and Windows containers. But it's not possible to modify the binfmt_misc file via the --privileged flag:
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: Windows does not support privileged mode.
See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.
Current (1803-era) versions of Hyper-V HCS run a real Linux kernel, not a WSL one. I guess it should be possible to modify the host's binfmt_misc directory.
How is it possible to run a Linux/ARM container image on a Windows/x86_64 Docker host running LCOW?
Is it possible to modify the Linux host image used by LCOW?
Is there any other way to get a unified docker daemon that is capable of running Windows/x86_64, Linux/x86_64 and Linux/ARM Docker images?

Unable to run Docker without sudo on AMI linux EC2 instance on AWS

I am unable to run Docker on AMI linux EC2 instance on AWS. My AMI linux instance is Linux ip-172-31-29-77 4.14.62-65.117.amzn1.x86_64 #1 SMP Fri Aug 10 20:03:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux.
I am able to install docker and start the service using:
sudo yum install -y docker
sudo service docker start
sudo usermod -aG docker ec2-user
but cmd docker ps does not work?
can anyone help me on this?
Thanks,
Nidhi Arora
You have done all the steps correctly. I believe your goal here is to run docker commands without sudo.
However after adding user to the docker (Or any) group, you have to refresh the user's group id.
You can either login again or do su - $USER.
You can run id before and after to confirm.
On Amazon Linux, if you do not know the password of ec2-user, just restart the EC2 instance to refresh the addition of ec2-user to the 'docker' group.

Version of Ubuntu being used in a docker container

I'm trying to figure out the version of Ubuntu being used in a docker container.
This Verfiy the version of ubuntu running in a Docker container mentions cat /etc/lsb-release which gives:
cat: can't open '/etc/lsb-release': No such file or directory
and uname -r gives:
3.13.0-119-generic
FWIW, uname -a gives:
Linux <container id> 3.13.0-119-generic #166-Ubuntu SMP Wed May 3 12:18:55 UTC 2017 x86_64 Linux
Any ideas what version of Ubuntu it might be? Or how else I can find this out?
Try lsb-release -a or cat /etc/issue
Just docker history --no-trunc your_image will show, among other things the FROM ... line

How does Docker run a Linux kernel under macOS host?

I installed Docker on my macOS Sierra as follows. Note I don't have VirtualBox installed.
brew cask uninstall virtualbox
brew cask install docker
My macOS details.
$ uname -a
Darwin m-C02QG7TRG8WN.local 16.5.0 Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
$ docker version
Client:
Version: 17.03.1-ce
API version: 1.27
Go version: go1.7.5
Git commit: c6d412e
Built: Tue Mar 28 00:40:02 2017
OS/Arch: darwin/amd64
Server:
Version: 17.03.1-ce
API version: 1.27 (minimum version 1.12)
Go version: go1.7.5
Git commit: c6d412e
Built: Fri Mar 24 00:00:50 2017
OS/Arch: linux/amd64
Experimental: true
Once I run Docker from launchpad, I am able to run Docker containers.
$ docker run -it ubuntu
root#2351d4222a4e:/# uname -a
Linux 2351d4222a4e 4.9.13-moby #1 SMP Sat Mar 25 02:48:44 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
My question is how does Docker manage to run a Linux kernel within macOS? I thought Docker would at least require boot2docker or some other such Linux kernel running so that it can create the Ubuntu's filesystem with the help of it. But the above output seems to indicate that it is not so. Where does the Linux kernel come from then?
While the other answers are correct about the hypervisor, they don't answer your specific question.
The answer is "Docker [Desktop] for Mac" does run a Linux host VM with a replacement for boot2docker - LinuxKit developed and maintained by Docker for the purpose of making lightweight distributions.
https://blog.docker.com/2017/04/introducing-linuxkit-container-os-toolkit/
The uname you saw didn't have the keyword in it, but it seems to be included now, e.g. from Docker for Mac 18.03.1 I see:
Linux a8e079429a51 4.9.87-linuxkit-aufs #1 SMP Wed Mar 14 15:12:16 UTC 2018 x86_64 Linux
You can see links to the included versions on the release pages.
https://docs.docker.com/docker-for-mac/release-notes/
So it's not so different from the old days Docker Machine + VirtualBox + boot2docker,
for the new days, it's just
the provisioning is done internally by "Docker [Desktop] for Mac"
and VirtualBox is replaced by Apple's Hyperkit,
and the "default VM" is a bit more tucked away.
The early version Docker used VirtualBox to run virtual machine for Docker. Since June 2016, the way to run Docker on Mac and Windows became much simpler, there's the official release introduction blog for Docker on Mac/Windows, and there's also some introduction from docker mac website:
Docker for Mac is a complete development environment deeply integrated with the MacOS Hypervisor framework, networking and filesystem.
And with the structure looks like:
Docker is using Apple's Hypervisor Framework: https://developer.apple.com/reference/hypervisor
More reading on the Docker blogs for when then came out last year: https://blog.docker.com/2016/05/docker-unikernels-open-source/

Resources