From Yocto Project
Jump to: navigation, search

This assumes you'd like to build an image that supports docker on a YP image. This is pretty straightforward due to the great work done on the meta-virtualization layer, mostly by people at Wind River. This document will show how to get docker running on a Nuc. I have run the same image on a Minnowboard (Turbot) successfully as well. Note, these layers change, so this is accurate as of July 2017.


What Layers Do You Need?

The main layer is meta-virtualization. This can be found using the layers.openembedded search app, Here's the [meta-virtualiation] entry. As you can see from the dependency list, this layer requires oe-core,meta-oe, meta-networking, and meta-filesystems. Some of these (like meta-networking) have additional dependencies. Here's the complete list of additional layers you need:

You need to add these (with absolute paths) to your build/conf/bblayers.conf file. BBLAYERS should look something like this:

BBLAYERS ?= " \                                                                                                                                          
 <AbsPath>/poky/meta \                                                                                                                                  
 <AbsPath>/poky/meta-poky \                                                                                                                             
 <AbsPath>/poky/meta-yocto-bsp \                                                                                                                        
 <AbsPath>/meta-openembedded/meta-oe \                                                                                                                  
 <AbsPath>/meta-openembedded/meta-python \                                                                                                              
 <AbsPath>/meta-openembedded/meta-networking \                                                                                                          
 <AbsPath>/meta-openembedded/meta-filesystems \                                                                                                         
 <AbsPath>/meta-virtualization \                        

What Configuration Changes Do you Need?

There are a number of configuration settings you need in your build/conf/local.conf in order to make this work. I'll list them below and try to explain why you need them:

# this gives us the linux-yocto kernel for an x86-64 machine like minnowboard                                                                            
MACHINE = "genericx86-64"
# Docker presumes systemd                                                                                                                                 
DISTRO_FEATURES_append = " systemd"
VIRTUAL-RUNTIME_init_manager = "systemd"
VIRTUAL-RUNTIME_initscripts = "systemd-compat-units"
# we need space for images                                                                                                                               
# The extra space takes us above 4gb, so                                                                                                                 
# turn off hdd and iso images so they do                                                                                                                 
# not break                                                                                                                                              
# pick a kernel I know works:                                                                                                                            
# add docker to the image                                                                                                                                
# connman to manage the networking                                                                                                                       
IMAGE_INSTALL_append = "  docker docker-contrib connman connman-client \                                                                                 

Current Hacks Needed

Some of this is not upstreamed yet, so here's some patches you may need to apply. Check and see of they have been accepted upstream or not, first...

Proxy problems

Once on the target board, you need to tell docker about your proxy (if you have one). This is a little hard to do by hand, so here are a couple of files you can insert into meta-virtualization to help you along.

meta-virtualization$ cat recipes-containers/docker/docker_git.bbappend

SRC_URI += "file://http-proxy.conf"
do_install_append() {
   if [ -n "${http_proxy}" ]; then
       install -d ${D}/$docker_config_dir
       sed -e s_{URL}_${http_proxy}_ ${WORKDIR}/http-proxy.conf > ${D}/$docker_config_dir/http-proxy.conf
meta-virtualization$ cat recipes-containers/docker/files/http-proxy.conf

What To Build

Once these are all in place, you are ready to make your image. I'd suggest building core-image-base. Note: core-image-mininal will NOT work since it does not include the kernel module packages by default.

$bitbake core-image-base

How to get the image onto your usb key

You need to check (lsusb or dmesg) to see that /dev/sdX your usb key showed up as.

  • sudo umount /dev/sdX1;sudo umount /dev/sdX2; <unmount any others as well>
    • slow way
      • sudo dd if=tmp/deploy/images/genericx86-64/core-image-base-genericx86-64.wic of=/dev/sdX
    • fast way
      • bitbake bmap-tools-native -caddto_recipe_sysroot
      • sudo chmod 666 /dev/sdX
      • oe-run-native bmap-tools-native bmaptool copy ./tmp/deploy/images/genericx86-64/core-image-base-genericx86-64.wic /dev/sdX

How to Test

You can now log onto your target Minnowboard, and you can test out docker, which should be running.

$root@genericx86-64:~# docker info
Containers: 0
 Running: 0
 Paused: 0
Stopped: 0
Images: 0
Server Version: 1.13.0
Storage Driver: vfs
Logging Driver: json-file
Cgroup Driver: cgroupfs
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 03e5862ec0d8d3b3f750e19fca3ee367e13c090e
runc version: 2f7393a47307a16f8cee44a37b262e8b81021e3e
init version: N/A (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Kernel Version: 4.9.31-yocto-standard
 Operating System: Poky (Yocto Project Reference Distro) 2.3 (pyro)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
Total Memory: 7.618 GiB
Name: genericx86-64
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Http Proxy:
WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
Experimental: false
Insecure Registries:
Live Restore Enabled: false
$ docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
27144aa8f1b9: Pull complete 
Digest: sha256:be3c11fdba7cfe299214e46edc642e09514dbb9bbefcd0d3836c05a1e0cd0642
Status: Downloaded newer image for busybox:latest

$ docker run -it --rm busybox sh
/ #

If there are issues try systemctl status docker to see what went wrong.

Personal tools