LoginSignup
10
9

More than 1 year has passed since last update.

Zscaler 環境下で作る WSL2(Ubuntu 20.04) + Docker 環境

Last updated at Posted at 2022-11-01

Docker 環境を用意するにあたって、Docker Desktop は有料化されているので、Docker Desktop を利用せずに Docker 環境を用意しました。

なお、現時点この手順でインストールされる WSL のバージョンでは systemd がサポートされないため利用時に起動する手間が発生しますが、正式にサポートされるようではあります。

Systemd support is now available in WSL!

環境

Zscaler 環境下で動作する Windows 11 22H2

インストールするもの

  • WSL2(Ubuntu 20.04)
  • Docker CE
  • Docker Compose

WSL2 のインストール

パワーシェルを管理者権限で開き、以下のコマンドを実行すると WSL2 がインストールされます。

> wsl --install -d ubuntu

名前解決に失敗するので、DNS サーバの設定を変更する

sudo apt-get updateを実行すると、以下のように名前解決に失敗していた。

$ sudo apt-get update
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://ppa.launchpad.net/git-core/ppa/ubuntu focal InRelease
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2196 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [972 kB]
Ign:8 https://download.docker.com/linux/ubuntu focal InRelease
Err:9 https://download.docker.com/linux/ubuntu focal Release
  Could not wait for server fd - select (11: Resource temporarily unavailable) [IP: 205.251.193.112 443]
Reading package lists... Done
E: The repository 'https://download.docker.com/linux/ubuntu focal Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

これに対応するため、/etc/resolv.confを手動で作成します。

  1. コマンドプロプトでbashコマンドを叩くいて WSL に接続する
  2. /etc/resolv.confを自動的に生成しないように/etc/wsl.confを作成し、以下の記載を追加する
    [network]
    generateResolvConf = false
    
  3. /etc/resolv.confを作成する(環境に応じて適切な DNS サーバーを設定)
    # 既に作成されているので一度削除
    $ sudo rm /etc/resolv.conf
    # ここではGoogleが提供するDNSサーバとしています
    $ sudo vi /etc/resolv.conf
    ---
    nameserver 8.8.8.8
    nameserver 8.8.4.4
    
  4. /etc/resolv.confが WSL のシャットダウン時に削除されてしまうため、属性を変更しておく
    $ sudo chattr +i /etc/resolv.conf
    
  5. WSL を抜けた後で、コマンドプロンプトから WSL を再起動する
    > wsl --shutdown
    

Zscaler のルート証明書の登録

Ubuntu 20.04 には Zscaler のルート証明書が登録されていないため、ルート証明書を登録します。

  1. Windows+R キー ファイル名を指定して実行からcertmgr.mscを実行する
  2. 信頼されたルート証明機関->証明書にある Zscaler のルート証明を開く
  3. 「詳細」タブの「ファイルにコピー(C)...」から Base 64 encoded X.509 形式で証明書をエクスポートする
  4. エクスポートした証明書を WSL に登録する
    $ sudo cp -p zscaler.crt /usr/local/share/ca-certificates/
    $ sudo update-ca-certificates --fresh
    

Docker のインストールと起動

Docker をインストールおよび起動します。

# パッケージ一覧の更新
$ sudo apt update
# パッケージのインストール
$ sudo apt install ca-certificates curl gnupg lsb-release
# Dockerのofficial_GPG_key追加
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Dockerリポジトリ情報の登録
$ echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# パッケージ一覧を更新
$ sudo apt update
# Docker Engine のインストール(dockerユーザおよびグループが作成される)
$ sudo apt install docker-ce docker-ce-cli containerd.io
# Docker Group にユーザを所属させる
$ sudo usermod -aG docker $USER
# 起動
$ sudo /etc/init.d/docker start

Docker Compose のインストール

Docker Compose をインストールします。

$ DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
$ mkdir -p $DOCKER_CONFIG/cli-plugins
$ curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
$ chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose

参考

10
9
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
10
9