LoginSignup
15
14

More than 1 year has passed since last update.

ChromebookにDockerを導入

Last updated at Posted at 2022-07-30

概要

chromebookでNode.jsとPHPの環境を構築してきたが、やはりローカルの環境を汚さず色々な環境を即座に用意できるDockerは便利。
環境構築の手間をかけず同じ環境を配布できるし、コンテナごとデプロイなんてこともできるため業務でも使うことは多く、仕事で使うPCではやはり使えるようになっていて欲しい。
ということで、環境を構築したのでその備忘録。

目次

  • Docker ?
  • Docker Desktop for linux について
  • Dockerをインストール
  • sudoなしでDockerを使用できるようにする

Docker ?

  • コンテナ仮想化を用いてアプリケーションを開発・配置・実行するためのオープンプラットフォーム
  • ホストOSのカーネルを使う辺り、OSを丸ごとインストールする仮想マシンとは、ちょっと違う
  • Build, Ship, and Run Any App, Anywhere だそうな
  • ローカル環境を汚さずいろんなものコンテナに入れて構築できる便利なやつ
  • チームで開発するときとか、(ほぼ)同じ環境を簡単に用意できて楽ちん

Docker Desktop for Linux

Linuxでも windowsやMacOSと同様、Docker Desktopがリリースされました
システム要件は以下の通り

System requirements

To install Docker Desktop successfully, your Linux host must meet the following requirements:

  • 64-bit kernel and CPU support for virtualization

  • KVM virtualization support. Follow the KVM virtualization support instructions to check if the KVM kernel modules are enabled and how to provide access to the kvm device.

  • QEMU must be version 5.2 or newer. We recommend upgrading to the latest version.

  • systemd init system.

  • Gnome or KDE Desktop environment. -For many Linux distros, the Gnome environment does not support tray icons. To add support for tray icons, you need to install a Gnome extension. For example, AppIndicator).

  • At least 4 GB of RAM.

Docker Desktop for Linux runs a Virtual Machine (VM). For more information on why, see Why Docker Desktop for Linux runs a VM.

要するに、仮想マシン上で動かすので「cpuが対応してるか」「KVMカーネルモジュールが有効か」等々の要件がありますよ、と

正直、要件を満たしていない、もしくは要件を満たすための作業が煩雑であることが多いと予想されるため、今回はDocker Desktopは使いません
カーネルモジュール周りが私のChromebookだとややこしかったので

Dockerをインストール

Docker Engineをインストールしていく
CrostiniはDebianベースなので、基本的にDebianへのインストール方法に沿って進める。
※ 公式ではapt-getを使っているが、今回はaptを使用

古いverを削除

bash.
$ sudo apt remove docker docker-engine docker.io containerd runc

レポジトリをセットアップ

  • aptパッケージを更新
  • HTTPS上のレポジトリ使用に必要なパッケージをインストール
bash.
$ sudo apt install

$ sudo apt install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
bash.
$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  • 以下のコマンドでレポジトリをセットアップ
bash.
 echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Docker Engineをインストール

  • Docker Engine, containerd, DockerComposeをインストール
bash.
$ sudo apt update
$ sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin

apt updateでエラーが出る場合は以下のコードを試す

bash.
$ sudo chmod a+r /etc/apt/keyrings/docker.gpg

Dockerの動作確認

  • テストイメージで動作確認
bash.
$ sudo docker run hello-world

下のように出力されると成功

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:80f31da1ac7b312ba29d65080fddf797dd76acfb870e677f390d5acba9741b17
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

これでインストール作業は完了

sudoなしでも動作するように設定

インストールしただけだとdockerコマンドに全てsudoが必要
コマンド入力やファイル編集時の手間を軽減するため、Dockerというグループを作成し、ユーザー権限を設定します

dockerグループを作成

なければ以下のコマンドで作成

bash.
$ sudo groupadd docker

グループにユーザーを追加

作ったグループにユーザーを追加
($USERはユーザー名が入ってる変数なのでそのまま使える。ユーザー名をベタ打ちしてももちろんok)

bash.
$ sudo usermod -aG docker $USER

linuxコンテナを再起動するとグループの変更が有効になります。
以下のコマンドを実行してもOK。

bash.
$ newgrp docker

これで、Dockerコマンドがsudoなしで使えるようになります

chromebook環境構築関連の記事

ChromebookにNode.js開発環境を構築する
chromebookへのphp開発環境構築(Xampp)

15
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
14