見出し画像

プロのインフラエンジニアが、incus で Docker してみた。 ③ ~ Docker 編 ~

では、Docker をインストールしていきましょう。Docker 用の incus コンテナを作成します。

incus launch images:ubuntu/noble Docker --profile=bridge

の、■少しだけコンテナを使ってみる で、やった root パスワードの設定、ユーザーの作成、sshサーバのインストールを済ませておきます。Docker を incus コンテナにインストールするには、ネスティングの設定が必要になります。ネストって、ココでは入れ子ね。

incus config set Docker security.nesting true

Docker はコンテナ名です。それでは、また Docker コンテナのコンソールに入って、前提になるアプリを入れていきます。

sudo apt install ca-certificates curl gnupg lsb-release -y

次に、DockerのGPGの鍵と、リポジトリをaptに登録します。

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Docker のリポジトリにアクセスできるようになったので、

sudo apt update

で、リポジトリを再取得して、

sudo apt install docker-ce docker-ce-cli containerd.io -y

で、インストールします。終わったらインストールを確認します。

docker --version

Docker version 27.1.2, build d01f264 と出ました。インストール完了です。incus の時と同じに、docker 実行権をユーザーに付けていきます。

sudo adduser ユーザー名 docker
newgrp docker

では、何かコンテナを入れてみましょう

docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:53cc4d415d839c98be39331c948609b659ed725170ad2ca8eb36951288f81b75
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/

キチンと入って動いています。OK、Docker の実行環境もできました。

コレで、incus と、Docker の実行環境構築完了です。環境ができたので、これから一つ一つ勉強していこうと思います。

手始めに、プロキシから作ってみましょうか

docker pull ubuntu/squid

で、イメージをダウンロードして、

docker run -it -d --restart always --name squid -e TZ=Asia/Tokyo -p 3128:3128 ubuntu/squid

と、実行します。

docker logs -f squid

で、ログが見れればOK。時間も日本標準時を確認。ブラウザでプロキシを設定して、サイトをみると、ログが流れるので、これも確認。ctrl + c で抜けます。

って、感じでコンテナって有りものをダウンロードして、ランさせるだけでサーバーができちゃう。これも利点の一つだねぇ。コンテナを自分で作る場合は、それなりに勉強が必要。私もコレからになります。

実は最初に、chrony あたりをコンテナイメージダウンロードして入れようと思ったんですが、よくよく考えると、コンテナの日付時間は、コンテナエンジンの乗ってるホストの日付時間が、そのまま適用されるわけですよ。と、いうことは、コンテナで、chrony 入れてもどうなるんだろう?と、疑問が晴れなくて、結局ホストOSに、chrony 入れて NICT と時刻同期するようにしました。

現行 LAN 内の NTP などを色々なサービスを実装しているサーバ(さっきのプロキシもここ)は、サービスを全部コンテナに移管して、削除する予定なので、この chrony が、LAN内に時間を供給するようになります。NTPはIPアドレス変更かぁ、面倒だなぁ。いっそのこと、コンテナでも chrony 実装して、配るのはソコからにしようか。。。まぁ考えます。

作ったり、消したり、再起動したりが簡単なコンテナ技術。皆さんも如何でしょうか。

この記事が気に入ったらサポートをしてみませんか?