How to install Docker on Gentoo

  7 mins read  

How to install Docker on Gentoo

We already have a tutorial for Docker for beginners that can be consulted here. But in this article we’ll show you the steps on Gentoo.

1. Enable modules in Kernel

Open the Kernel configuration menu

su
cd /usr/src/linux
make menuconfig

And enable the modules

General setup  --->
    [*] POSIX Message Queues
    -*- Control Group support  --->
        [*]   Memory controller 
        [*]     Swap controller
        [*]       Swap controller enabled by default
        [*]   IO controller
        [ ]     IO controller debugging
        [*]   CPU controller  --->
              [*]   Group scheduling for SCHED_OTHER
              [*]     CPU bandwidth provisioning for FAIR_GROUP_SCHED
              [*]   Group scheduling for SCHED_RR/FIFO
        [*]   PIDs controller
        [*]   Freezer controller
        [*]   HugeTLB controller
        [*]   Cpuset controller
        [*]     Include legacy /proc/<pid>/cpuset file
        [*]   Device controller
        [*]   Simple CPU accounting controller
        [*]   Perf controller
        [ ]   Example controller 
    -*- Namespaces support
        [*]   UTS namespace
        -*-   IPC namespace
        [*]   User namespace
        [*]   PID Namespaces
        -*-   Network namespace
-*- Enable the block layer  --->
    [*]   Block layer bio throttling support
    -*- IO Schedulers  --->
        [*]   CFQ IO scheduler
            [*]   CFQ Group Scheduling support   
[*] Networking support  --->
      Networking options  --->
        [*] Network packet filtering framework (Netfilter)  --->
            [*] Advanced netfilter configuration
            [*]  Bridged IP/ARP packets filtering
                Core Netfilter Configuration  --->
                  <*> Netfilter connection tracking support 
                  *** Xtables matches ***
                  <*>   "addrtype" address type match support
                  <*>   "conntrack" connection tracking match support
                  <M>   "ipvs" match support
            <M> IP virtual server support  --->
                  *** IPVS transport protocol load balancing support ***
                  [*]   TCP load balancing support
                  [*]   UDP load balancing support
                  *** IPVS scheduler ***
                  <M>   round-robin scheduling
                  [*]   Netfilter connection tracking
                IP: Netfilter Configuration  --->
                  <*> IPv4 connection tracking support (required for NAT)
                  <*> IP tables support (required for filtering/masq/NAT)
                  <*>   Packet filtering
                  <*>   IPv4 NAT
                  <*>     MASQUERADE target support
                  <*>   iptables NAT support  
                  <*>     MASQUERADE target support
                  <*>     NETMAP target support
                  <*>     REDIRECT target support
        <*> 802.1d Ethernet Bridging
        [*] QoS and/or fair queueing  ---> 
            <*>   Control Group Classifier
        [*] L3 Master device support
        [*] Network priority cgroup
        -*- Network classid cgroup
Device Drivers  --->
    [*] Multiple devices driver support (RAID and LVM)  --->
        <*>   Device mapper support
        <*>     Thin provisioning target
    [*] Network device support  --->
        [*]   Network core driver support
        <M>     Dummy net driver support
        <M>     MAC-VLAN support
        <M>     IP-VLAN support
        <M>     Virtual eXtensible Local Area Network (VXLAN)
        <*>     Virtual ethernet pair device
    Character devices  --->
        -*- Enable TTY
        -*-   Unix98 PTY support
        [*]     Support multiple instances of devpts (option appears if you are using systemd)
File systems  --->
    <*> Overlay filesystem support 
    Pseudo filesystems  --->
        [*] HugeTLB file system support
Security options  --->
    [*] Enable access key retention support
    [*]   Enable register of persistent per-UID keyrings
    <M>   ENCRYPTED KEYS
    [*]   Diffie-Hellman operations on retained keys

2. Make sure you have enabled all modules correctly

For this you can use a Bash script: check-config.sh

wget https://git.io/check-config.sh
chmod +x check-config.sh
sh check-config.sh

The output will look like this: Chech config Docker Kernel modules

If there are not enabled modules (missing), check first if your Kernel version has this module name, example for the module *CONFIG_EXT3_FS_XATTR:

grep 'CONFIG_EXT3_FS_XATTR' /usr/src/linux/.config

If you do not return the output it is because you do not have it, but if you return, copy the name of the module and search on any screen of the Kernel menu, pressing the bar (/) will open a box for you to enter the name you want to search, just paste the name you had copied and then press Enter, example:

Researched the module: CONFIG_NETFILTER_XT_MATCH_IPVS search module kerne

Result with complete path and all data:

Symbol: NETFILTER_XT_MATCH_IPVS [=m]
Type  : tristate
Prompt: "ipvs" match support
  Location: 
    -> Networking support (NET [=y])
       -> Networking options
        -> Network packet filtering framework (Netfilter) (NETFILTER [=y])
          -> Core Netfilter Configuration
(1)         -> Netfilter Xtables support (required for ip_tables) (NETFILTER_XTABLES [=y])
  Defined at net/netfilter/Kconfig:1322
  Depends on: NET [=y] && INET [=y] && NETFILTER [=y] && NETFILTER_XTABLES [=y] && IP_VS [=m] && NETFILTER_ADVANCED [=y] && NF_CONNTRACK [=y]

result module

The line Prompt indicates the name that it is in the menu and in Location the complete path to find it.

In this case, it is enabled as a module: [=m], but if it is as is not set it will be necessary to enable it.

3. Compile the Kernel

make && make modules_install && make install

4. Install and configure Docker

emerge --ask --verbose app-emulation/docker

Add your user to the docker group

usermod -aG docker <username>

If you want to add Docker to start with OpenRC

rc-update add docker default

If you do not want it to start together with the system, to use Docker you will always have to start it manually: rc-service docker start. If you use systemd run: systemctl start docker.service.

Restart your system so that some modules are read at startup and your user’s group change takes effect: sudo reboot.

# Testing if everything is right
docker info

Useful links:

Watch a video about Docker

Join our Facebook group