3

Running docker on a Mac

docker pull ubuntu:14.04
docker run -i -t ubuntu:14.04 /bin/bash

Linux Standard Base

root@d112db1e835e:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:    14.04
Codename:   trusty

My goal is to retire a dedicated laptop that I used to build some good old C code and use a docker container instead.

In order to compile my code, my Makefile is looking to run

Makefile:       /usr/bin/make -C /lib/modules/$(shell uname -r)/build M=$(PWD)/linux/$* modules

unfortunately the modules folder is empty

mysuer@d112db1e835e:~/robot$ ls -al /lib/modules/
ls: cannot access /lib/modules/: No such file or directory

On my linux machine, I can find the modules

$ ls -al /lib/modules/
total 28
drwxr-xr-x  7 root root 4096 Dez 13  2016 .
drwxr-xr-x 24 root root 4096 Apr 24  2017 ..
drwxr-xr-x  5 root root 4096 Dez 13  2016 3.13.0-105-generic
drwxr-xr-x  5 root root 4096 Jun 23  2015 3.13.0-55-generic
drwxr-xr-x  5 root root 4096 Jul 10  2015 3.13.0-57-generic
drwxr-xr-x  5 root root 4096 Nov  3  2015 3.13.0-65-generic
drwxr-xr-x  5 root root 4096 Nov 24  2015 3.13.0-68-generic

but no modules in my docker.

On my docker

uname -r
4.9.60-linuxkit-aufs

hence

/usr/bin/make -C /lib/modules/4.9.60-linuxkit-aufs/build .... FAILS

/lib/modules/4.9.60-linuxkit-aufs is not there.

How do I work around that?

Trying to install headers

apt-cache search linux-headers-4
linux-headers-4.2.0-18 - Header files related to Linux kernel version 4.2.0
linux-headers-4.2.0-18-generic - Linux kernel headers for version 4.2.0 on 64 bit x86 SMP
linux-headers-4.2.0-18-lowlatency - Linux kernel headers for version 4.2.0 on 64 bit x86 SMP
linux-headers-4.2.0-19 - Header files related to Linux kernel version 4.2.0
linux-headers-4.2.0-19-generic - Linux kernel headers for version 4.2.0 on 64 bit x86 SMP
linux-headers-4.2.0-19-lowlatency - Linux kernel headers for version 4.2.0 on 64 bit x86 SMP
linux-headers-4.2.0-21 - Header files related to Linux kernel version 4.2.0
linux-headers-4.2.0-21-generic - Linux kernel headers for version 4.2.0 on 64 bit x86 SMP
linux-headers-4.2.0-21-lowlatency - Linux kernel headers for version 4.2.0 on 64 bit x86 SMP
linux-headers-4.2.0-22 - Header files related to Linux kernel version 4.2.0
...

I don't find headers for 4.9.60

root@d112db1e835e:~#  apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package linux-headers-4.9.60-linuxkit-aufs
E: Couldn't find any package by regex 'linux-headers-4.9.60-linuxkit-aufs'

or

root@d112db1e835e:~# apt-cache search linux-headers-4.9
root@d112db1e835e:~# 

no candidate

root@d112db1e835e:~# apt-get install linux-headers 
Reading package lists... Done
Building dependency tree        
Reading state information... Done
Package linux-headers is a virtual package provided by:
  linux-headers-4.4.0-1010-aws 4.4.0-1010.10
  linux-headers-4.4.0-1009-aws 4.4.0-1009.9
... FILTERED ...
  linux-headers-3.13.0-100-lowlatency 3.13.0-100.147
  linux-headers-3.13.0-100-generic 3.13.0-100.147
You should explicitly select one to install.

E: Package 'linux-headers' has no installation candidate
root@d112db1e835e:~# 

doesn't return any packages

root@d112db1e835e:~# apt-cache search linux-source     
linux-source - Linux kernel source with Ubuntu patches
linux-source-3.13.0 - Linux kernel source for version 3.13.0 with Ubuntu patches
  • 1
    I seem to be having the same issue on Ubuntu 16.04 image in Docker on my mac. This does not directly answer your question but you could try installing the linux-headers-generic package. When I did that, linux-headers-4.4.0-112 was also installed for me. – Karthic Raghupathi Jan 27 '18 at 16:04
  • 1
    Is there any reason why you want to use a docker container for this instead of a VM (e.g. with VirtualBox)? Containers are typically made with the bare minimum required to run just one thing. They are also usually ephemeral, with any "state" (e.g. files, data, configuration settings, etc) stored outside of the container so that the container can be disposed of (and new instance(s) started as needed) without losing any data. They're meant to be small, short-lived and disposable. VMs are virtualised complete systems, meant to be long-lived. – cas Jan 28 '18 at 9:30
5

Docker for Mac is built with Hyperkit for Virtualization(see FAQ), and runs a linuxkit kernel (which you already know) which is custom built for running containers, so when it comes to doing lower level development with/related to the kernel it doesn't exactly work the same way as using a regular linux distribution.

I would highly recommend using QEMU for this type of work as you can emulate different types of hardware, use different BIOS, and even pxeboot using ipxe.

That being said, to answer your question, you will need to install linux-virtual to have a generic linux kernel for your container.

EDIT: also uname -r won't work since it will be a different kernel version. The default kernel version for trusty (14.04) is still 3.x

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.