Proxy 設定めんどくさいですよね。Docker の初期設定でいろいろつまづいたので、設定方法を書いておきます。ご参考になれば。
ちなみに確認環境は WSL Ubuntu20.04です。
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.4 LTS Release: 20.04 Codename: focal
apt 周りのプロクシ設定
下記の記事を参考に設定してください。WSL でもUbuntuでも同じです。
https://hangstuck.com/wsl-proxy-setting/
特に apt.confの設定を忘れないでください。ここを間違えると下記のように「そんなもんDockerリポジトリには存在せんぞ」と怒られてしまいます。
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
$ sudo apt-get update
Ign:1 https://download.docker.com/linux/ubuntu focal InRelease
Err:2 https://download.docker.com/linux/ubuntu focal Release
Could not handshake: An unexpected TLS packet was received. [IP: XX.XX.XX.XX:YY]
Hit:3 http://security.ubuntu.com/ubuntu focal-security InRelease
Get:4 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Reading package lists... Done
E: The repository 'https://download.docker.com/linux/ubuntu focal Release' does not have 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.
DockerデーモンのProxy設定
さらに下記のように設定が必要です。/etc/default/docker というファイルがあるはずです。そこにコメントアウトされた状態でProxyの設定例が書いてあります。そこを自分の環境に合わせて修正します。
$ cat /etc/default/docker # Docker Upstart and SysVinit configuration file # # THIS FILE DOES NOT APPLY TO SYSTEMD # # Please see the documentation for "systemd drop-ins": # https://docs.docker.com/engine/admin/systemd/ # # Customize location of Docker binary (especially for development testing). #DOCKERD="/usr/local/bin/dockerd" # Use DOCKER_OPTS to modify the daemon startup options. #DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4" # If you need Docker to use an HTTP proxy, it can also be specified here. export http_proxy="http://username:password@proxy-host:proxy-port" export https_proxy="http://username:password@proxy-host:proxy-port" export ftp_proxy="http://username:password@proxy-host:proxy-port" # This is also a handy place to tweak where Docker's temporary files go. #export DOCKER_TMPDIR="/mnt/bigdrive/docker-tmp"
さらに、systemctl の設定も行います。
$ sudo systemctl edit docker
と実行するとエディタが開きますので下記のようにProxyを設定してください。
[Service] Environment="HTTP_PROXY=http://proxy-host:proxy-port/" Environment="HTTPS_PROXY=http://proxy-host:proxy-port/"
コンテナ起動時のプロキシ設定
コンテナの作成もしくは起動時に、環境変数がコンテナ内へ自動的に設定するように設定ファイルを作成します。
下記のサイトにあるようにホスト側に ~/.docker/config.json を作ればOKです。
https://docs.docker.jp/network/proxy.html
下記のような感じですね。noProxy は不要ならなくても大丈夫かと思います。
$ mkdir -p ~/.docker/
$ vim ~/.docker/config.json
$ cat ~/.docker/config.json
{
"proxies":
{
"default":
{
"httpProxy": "http://192.168.1.12:3128",
"httpsProxy": "http://192.168.1.12:3128",
"noProxy": "*.test.example.com,.example2.com,127.0.0.0/8"
}
}
}
まとめ
これでひとまずDockerイメージをプルしてHello Worldまではできると思います。


コメント