Red Hat OpenShift4 on Laptop, fedora:latest

# はじめに
Red Hat からリリースされている[OpenShift4](https://try.openshift.com/)
そろそろ試してみようかなと思いチャレンジしてみます！第二弾

前回は[ubuntu:latestで試してみました](https://qiita.com/imp555sti/items/3bd89853ac31c67f9872)が、結局失敗に終わってます。
気を取り直してfedora:latestでやってみます。

# 環境
- Docker for Windows
- fedora:lastest on docker

## Prerequisites

OSに関する要求事項。ハードルがかなり上がってます(笑)
dockerでできるのかなぁ!?

> CodeReady Containers requires the following system resources in order to run OpenShift:
> - 4 virtual CPUs (vCPUs)
> - 8 GB of memory
> - 35 GB of storage space

ちなみにdockerにしているのは、うちのNotePCをWindows10 HomeからWindows10 Proにアップグレードし、Hyper-V入れてDocker for Windowsを入れたら、Hyper-VもVMwareもVirtualBoxも動作しなくなっちゃったため
原因が良く分からないけど、HyperVisorが複数入っているのが原因っぽい

# fedora:latestの準備

NetworkManagerとlibvirtdを入れて有効化しないと先に進めなそうなので、下準備を行います。

```console
C:\Git\minishift4\fedora>docker pull fedora:latest
C:\Git\minishift4\fedora>docker run --privileged -d -p 80:80 --name nm fedora:latest /sbin/init
c:\Git\minishift4\Fedora>docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
a2bc11ac8e95        fedora:latest       "/sbin/init"        17 minutes ago      Up 17 minutes                           NM

```

コンテナIDをメモって

```console
C:\Git\minishift4\fedora>docker exec -it a2bc11ac8e95 /bin/bash
[root@a2bc11ac8e95 /]# yum -y install curl libvirt NetworkManager
[root@a2bc11ac8e95 /]# systemctl start NetworkManager
[root@a2bc11ac8e95 /]# systemctl enable NetworkManager
[root@a2bc11ac8e95 /]# systemctl start libvirtd
[root@a2bc11ac8e95 /]# systemctl enable libvirtd
[root@a2bc11ac8e95 /]# exit
```

出来上がったfedora:latestにNetworkManagerとlibvirtdを有効化したイメージをdocker imageとして登録します。

```console
c:\Git\minishift4\Fedora>docker commit a2bc11ac8e95 fedora:custom
sha256:c1968b0dc1da3a77c2273d981f4cbfc2e77495b58bb32f0408ce527188a7f5cb
```

# Dockerfile
こんな感じでまとめました。
RUNを細切れにしているのはcacheを効かせるためです(笑)

ちなみに『[Getting started with Red Hat CodeReady Containers](https://code-ready.github.io/crc/)』に記載のものとは以下を変えています。

[1.2. Installing CodeReady Containers](https://code-ready.github.io/crc/#installing-codeready-containers_gsg)

マニュアル上では`libvirtd` groupになっているけどもそんなグループはない`libvirt` groupに変更

> 2. **On Debian or Ubuntu**, perform the following steps:
> a. Add your user to the libvirtd group:

> ```console
$ sudo usermod -aG libvirtd $(whoami)
```
> b. Update your current session to apply the group change:

> ```console
$ newgrp libvirtd
```



```docker:Dockerfile
FROM fedora:custom

ENV USER_ID=minishift \
    GROUP_ID=libvirt

RUN ln -sf /usr/share/zoneinfo/Japan /etc/localtime

RUN yum -y --setopt=tsflags=nodocs update
RUN yum clean all

ARG DOCKER_UID=1001
ARG DOCKER_USER=minishift
ARG DOCKER_PASSWORD=minishift
RUN useradd -m --uid ${DOCKER_UID} --shell /bin/bash ${DOCKER_USER} && \
    echo ${DOCKER_USER}:${DOCKER_PASSWORD} | chpasswd
RUN gpasswd -a ${DOCKER_USER} wheel
RUN sed -e 's/^%wheel/#%wheel/g' -e 's/^# %wheel/%wheel/g' -i /etc/sudoers
RUN curl -sS https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/crc-linux-amd64.tar.xz -o /tmp/crc-linux-amd64.tar.xz

RUN xz -dc /tmp/crc-linux-amd64.tar.xz | tar xfv - && \
    mv crc-linux-*/crc /usr/local/bin/crc

USER ${DOCKER_USER}

WORKDIR /home/${DOCKER_USER}
EXPOSE 443

RUN crc setup

CMD [ "crc", "start" ]
```

```yaml:docker-compose.yaml
version: '3.7'
services:
  minishift:
    container_name: minishift
    build: ./
    image: minishift:4.1
    restart: always
```

# docker-compose buildするも失敗
Buildしてみるとubuntuの時と同じエラーが発生(汗
いや起動したイメージにしてるつもりなんだが…

**NetworkManager is required. Please make sure it is installed and running manually**

```console
C:\Git\minishift4>docker-compose build

:

Step 17/18 : RUN crc setup
 ---> Running in c37b1646fc77
level=info msg="Checking if NetworkManager is installed"
level=info msg="Checking if NetworkManager service is running"
level=fatal msg="NetworkManager is required. Please make sure it is installed and running manually"
ERROR: Service 'minishift' failed to build: The command '/bin/sh -c crc setup' returned a non-zero code: 1
```

何故なんだぁ～

```console
c:\Git\minishift4\Fedora>docker run --privileged -d --name hoge fedora:custom /sbin/init
fa8d7600e2f1be27afea2a53f20a9fbbac3a4c8fa126e7ca37ebd02389e4a9f6

c:\Git\minishift4\Fedora>docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
fa8d7600e2f1        fedora:custom       "/sbin/init"        4 seconds ago       Up 2 seconds                            hoge

c:\Git\minishift4\Fedora>docker exec -it fa8d7600e2f1 /bin/bash
[root@fa8d7600e2f1 /]# systemctl status NetworkManager
● NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-09-16 02:29:02 UTC; 44s ago
     Docs: man:NetworkManager(8)
 Main PID: 83 (NetworkManager)
    Tasks: 3 (limit: 2359)
   Memory: 14.2M
   CGroup: /docker/fa8d7600e2f1be27afea2a53f20a9fbbac3a4c8fa126e7ca37ebd02389e4a9f6/system.slice/NetworkManager.service
           └─83 /usr/sbin/NetworkManager --no-daemon
：
[root@fa8d7600e2f1 /]# systemctl status libvirtd
● libvirtd.service - Virtualization daemon
   Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-09-16 02:29:03 UTC; 1min 58s ago
     Docs: man:libvirtd(8)
           https://libvirt.org
 Main PID: 96 (libvirtd)
    Tasks: 19 (limit: 32768)
   Memory: 47.4M
   CGroup: /docker/fa8d7600e2f1be27afea2a53f20a9fbbac3a4c8fa126e7ca37ebd02389e4a9f6/system.slice/libvirtd.service
           ├─ 96 /usr/sbin/libvirtd
           ├─210 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
           └─211 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
：
```

ちゃんと動いてるイメージになっているはずなんだけどなぁ～

# じゃあ手作業でインストールしてみよう

意地になって手作業でインストールしちゃうんだから
名前なんて`hoge`で良い(笑)

```console
c:\Git\minishift4\Fedora>docker run --privileged -d --name hoge fedora:custom /sbin/init
fa8d7600e2f1be27afea2a53f20a9fbbac3a4c8fa126e7ca37ebd02389e4a9f6

c:\Git\minishift4\Fedora>docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
fa8d7600e2f1        fedora:custom       "/sbin/init"        4 seconds ago       Up 2 seconds                            hoge

c:\Git\minishift4\Fedora>docker exec -it fa8d7600e2f1 /bin/bash
```

Dockerfileに書いていることを一行筒ずつコマンド叩きます

```console
[root@fa8d7600e2f1 /]# ln -sf /usr/share/zoneinfo/Japan /etc/localtime
[root@fa8d7600e2f1 /]# yum -y --setopt=tsflags=nodocs update
[root@fa8d7600e2f1 /]# export DOCKER_UID=1001
[root@fa8d7600e2f1 /]# export DOCKER_USER=minishift
[root@fa8d7600e2f1 /]# export DOCKER_PASSWORD=minishift
[root@fa8d7600e2f1 /]# useradd -m --uid ${DOCKER_UID} --shell /bin/bash ${DOCKER_USER} && echo ${DOCKER_USER}:${DOCKER_PASSWORD} | chpasswd
[root@fa8d7600e2f1 /]# gpasswd -a ${DOCKER_USER} wheel
[root@fa8d7600e2f1 /]# sed -e 's/^%wheel/#%wheel/g' -e 's/^# %wheel/%wheel/g' -i /etc/sudoers
[root@fa8d7600e2f1 /]# curl -sS https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/crc-linux-amd64.tar.xz -o /tmp/crc-linux-amd64.tar.xz
curl: (23) Failed writing body (12288 != 16384)
```

おっとcurlでエラー発生（汗

```console
[root@fa8d7600e2f1 /]# curl -O https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/crc-linux-amd64.tar.xz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1702M  100 1702M    0     0  6623k      0  0:04:23  0:04:23 --:--:-- 6832k
[root@fa8d7600e2f1 /]# xz -dc crc-linux-amd64.tar.xz | tar xvf -
crc-linux-1.0.0-beta.3-amd64/
crc-linux-1.0.0-beta.3-amd64/LICENSE
crc-linux-1.0.0-beta.3-amd64/doc.pdf
crc-linux-1.0.0-beta.3-amd64/crc
[root@fa8d7600e2f1 /]# mv crc-linux-1.0.0-beta.3-amd64/crc /usr/local/bin/
[root@fa8d7600e2f1 /]# su - minishift
[minishift@fa8d7600e2f1 ~]$
```

いよいよ問題の`crc setup`です。

```console
[minishift@fa8d7600e2f1 ~]$ crc setup
INFO Checking if NetworkManager is installed
INFO Checking if NetworkManager service is running
INFO Caching oc binary
ERRO Error occurred: Download failed: write /tmp/crc396850476/oc.tar.gz: no space left on device
FATA Not able to download oc Download failed: write /tmp/crc396850476/oc.tar.gz: no space left on device
[minishift@fa8d7600e2f1 ~]$ df
Filesystem     1K-blocks     Used Available Use% Mounted on
overlay         61255652 56840872   1273448  98% /
tmpfs              65536        0     65536   0% /dev
tmpfs            1013980        0   1013980   0% /sys/fs/cgroup
shm                65536        0     65536   0% /dev/shm
/dev/sda1       61255652 56840872   1273448  98% /etc/hosts
tmpfs            1013980      352   1013628   1% /run
tmpfs            1013980  1013980         0 100% /tmp
[minishift@fa8d7600e2f1 ~]$ exit
[root@fa8d7600e2f1 ~]# rm -rf /tmp/*
[root@fa8d7600e2f1 ~]# su - minishift
[minishift@fa8d7600e2f1 ~]$ crc setup
INFO Checking if NetworkManager is installed
INFO Checking if NetworkManager service is running
INFO Caching oc binary
INFO Setting up virtualization
FATA You need to enable virtualization in BIOS
```

えっと…やぱりHyper-V入れてからダメだなぁ～