背景
インターネットから厳しく隔離された環境下でDockerをインストールすることになったが、どうしたものか頭を悩ました結果、以下の記事を発見。
こちらの記事を参考にさせて頂き、私の環境で実行した結果を備忘録として記録します。
手順の概要
- インターネットにつながる環境で必要なrpmをインストール
- ダウンロードしたrpmからリポジトリを作成する。
- リポジトリをインストールしたいサーバーに転送(今回はVSCodeを使った)後、ローカルインストールする
環境
- rpmダウンロード環境
- HyperV上にCentOS7のサーバーを構築
- 自身のPCで行ったのでインターネット接続可
CentOS Linux release 7.9.2009 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
CentOS Linux release 7.9.2009 (Core)
CentOS Linux release 7.9.2009 (Core)
- インストール先の環境
CentOS Linux release 7.9.2009 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
CentOS Linux release 7.9.2009 (Core)
CentOS Linux release 7.9.2009 (Core)
ダウンロード環境(HyperV上に構築したCentOS7サーバー)での作業
SELINUXをdisabled
vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
- SELINUX=enforcing
+ SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
firewall設定を無効化。
systemctl disable firewalld
再起動。
reboot
rpm をダウンロード
mkdir -p /work/dockerrpm
cd /work/dockerrpm
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yumdownloader --resolve docker-ce
yumdownloader
を実行すると、以下のようにrpmがインストールされる。
-rw-r--r-- 1 root root 78256 8月 23 2019 audit-libs-python-2.8.5-4.el7.x86_64.rpm
-rw-r--r-- 1 root root 302068 11月 12 2018 checkpolicy-2.5-8.el7.x86_64.rpm
-rw-r--r-- 1 root root 40816 7月 6 2020 container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm
-rw-r--r-- 1 root root 35297172 5月 12 04:55 containerd.io-1.6.21-3.1.el7.x86_64.rpm
-rw-r--r-- 1 root root 12781360 5月 26 21:22 docker-buildx-plugin-0.10.5-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 25540708 5月 26 21:22 docker-ce-24.0.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 14032028 5月 26 21:22 docker-ce-cli-24.0.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 9518692 5月 26 21:22 docker-ce-rootless-extras-24.0.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 12305416 5月 26 21:22 docker-compose-plugin-2.18.1-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 55796 4月 29 2020 fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm
-rw-r--r-- 1 root root 83764 4月 29 2020 fuse3-libs-3.6.1-4.el7.x86_64.rpm
-rw-r--r-- 1 root root 67720 8月 23 2019 libcgroup-0.41-21.el7.x86_64.rpm
-rw-r--r-- 1 root root 115284 11月 12 2018 libsemanage-python-2.5-14.el7.x86_64.rpm
-rw-r--r-- 1 root root 468316 4月 4 2020 policycoreutils-python-2.5-34.el7.x86_64.rpm
-rw-r--r-- 1 root root 32880 7月 4 2014 python-IPy-0.75-6.el7.noarch.rpm
-rw-r--r-- 1 root root 635184 11月 12 2018 setools-libs-3.3.8-4.el7.x86_64.rpm
-rw-r--r-- 1 root root 83452 4月 29 2020 slirp4netns-0.4.3-4.el7_8.x86_64.rpm
リポジトリ作成
createrepo
というものを利用して、Docker CEのリポジトリを作成する。コマンドが無かったので以下でインストール。
yum install -y createrepo
ダウンロードしたrpmがあるディレクトリを指定してリポジトリを作成する。
createrepo /work/dockerrpm
実行結果。
Spawning worker 0 with 5 pkgs
Spawning worker 1 with 4 pkgs
Spawning worker 2 with 4 pkgs
Spawning worker 3 with 4 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
成功するとrepodata
というディレクトリができる。ここにリポジトリのデータが入っている。
・・・
drwxr-xr-x 2 root root 4096 5月 27 21:14 repodata
・・・
次に、dockerrpm.repo
というリポジトリ設定を作成する。
[dockerrpm]
name=dockerrpm
baseurl=file:///work/dockerrpm
gpgcheck=0
インストール先へ転送するために、tar.gzにまとめる。
cd /
tar -zcvf dockerrpm.tar.gz work/dockerrpm
インストール先(インターネット接続不可)の環境で作業
tar.gz ファイルをインストール先へ転送
/dockerrpm.tar.gz
に配置した想定で進めます。
tar.gz ファイルを展開する。
cd /
tar -zxvf dockerrpm.tar.gz
yum-config-manager
で作成したリポジトリを追加する。
yum-config-manager --add-repo file:///work/dockerrpm/dockerrpm.repo
インターネット接続不可なので、余計なリポジトリ見に行かないように、今回作成したリポジトリのみ有効にする。
yum install -y --disablerepo=\* --enablerepo=dockerrpm /work/dockerrpm/docker-ce-24.0.2-1.el7.x86_64.rpm
インストールが完了すればOK。
インストール後の設定
起動と自動起動をON
systemctl start docker
systemctl status docker
systemctl enable docker
daemon.jsonの作成
default-address-pools
と コンテナのログ上限設定を設定した。
これについては、以下に記事を書いているので参考にして頂ければ幸いです。
{
"default-address-pools":[
{"base":"172.19.0.0/16", "size":24}
],
"data-root": "/data/docker-data",
"log-driver": "json-file",
"log-opts": {
"max-size": "1g",
"max-file": "5"
}
}
デーモンのリロードとDockerの再起動を実行。
systemctl daemon-reload
systemctl restart docker
systemctl status docker
動作確認(参考程度)
こちらの記事を参考にインターネットに繋がる環境でイメージをファイル保存して転送しておけば動作確認は可能です。
まとめ
最初にも載せましたが、こちらの記事のお陰でインターネットが接続できない環境でもDockerのセットアップができました。もし、同じ状況の方の参考になれば幸いです。