1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

docker.service.d/配下のconfに設定した認証付きproxy設定がdocker infoで表示されない時の対処法

Last updated at Posted at 2025-09-08

これは何?

上記を参考にDockerの認証付きproxy設定を行った際にsudo docker infoを実行してもHTTP Proxy: http://xxxxx:xxxxxx@example.com:81のようなproxy設定が表示されない事象を観測しました。

こちらの解決方法とその解説を本記事では行います。

環境

普遍的な話な気はするが一応記載

  • Windows11
    • WSL: 2.3.24.0
      • Ubuntu 22.04 LTS
  • systemd: 249.11-0ubuntu3.16
  • Docker: 26.0.0

解決方法

sigma:password%というクレデンシャルを使っていると仮定して記載します。

# NG例
sudo cat /etc/systemd/system/docker.service.d/override.conf
[Service]
Environment = 'http_proxy=http://sigma:password%@example.com:81'

まず、Environmentの値はシングルクォーテーション(')ではなく、ダブルクォーテーション(")を使って囲む必要があります。

さらに%に対してエスケープが必要です。systemdでは%%%と書く必要があり、URLの%%25にする必要があるので組み合わせて%%25と記載します。

sudo cat /etc/systemd/system/docker.service.d/override.conf
[Service]
Environment = "http_proxy=http://sigma:password%%25@example.com:81"

うまく行っている場合には以下のようにクレデンシャル情報がマスクして表示されます。

sudo docker info | grep Proxy                                                            
HTTP Proxy: http://xxxxx:xxxxx@example.com:81
HTTPS Proxy: http://xxxxx:xxxxx@example.com:81

Proxyの設定がうまくいっていなかったり、クレデンシャルが露出している場合にはproxyを使った通信に失敗します。設定を見直してください。

# password%をpassword%%でエスケープしようとした例
sudo cat /etc/systemd/system/docker.service.d/override.conf
[Service]
Environment = "http_proxy=http://sigma:password%%@example.com:81" "https_proxy=http://sigma:password%%@example.com:81"

# エスケープが失敗してクレデンシャルが露出している(通信にも成功しない)
sudo docker info | grep Proxy                                                            
HTTP Proxy: http://sigma:password%@example.com:81
HTTPS Proxy: http://sigma:password%@example.com:81

解説パート(暇な人向け)

systemdのconfファイルの仕様について

'がだめな理由と%%%としないといけない理由を記載します。

ENVIRONMENTの部分を見ると以下のような記述があります。

Environment=
Sets environment variables for executed processes. Each line is unquoted using the rules described in "Quoting" section in systemd.syntax(7) and becomes a list of variable assignments. If you need to assign a value containing spaces or the equals sign to a variable, put quotes around the whole assignment. Variable expansion is not performed inside the strings and the "$" character has no special meaning. Specifier expansion is performed, see the "Specifiers" section in systemd.unit(5).

これを見ると、ダブルクォーテーション(")を使うように記載されています。これが'が使えない解説でした。

また、Specifiers expansionについても記載されています。これは汎用的なconfファイルをかくために使われる置換子であり、%はSpecifire(置換子)をの始まりを表すメタ文字として使われています。

any settings resolve specifiers which may be used to write generic unit files referring to runtime or unit parameters that are replaced when the unit files are loaded. Specifiers must be known and resolvable for the setting to be valid. The following specifiers are understood:
Specifiers

# 使用例
ExecStart=/usr/bin/myapp --user=%i

今回のように%を文字して扱いたい場合には%%と記載する必要があります。

"%%" | Single percent sign | Use "%%" in place of "%" to specify a single percent sign.

URLエンコーディングについて

%%%%25にしないといけない理由を書きます。

rfc3986 2.1に以下のような記載があります。

A percent-encoding mechanism is used to represent a data octet in a component when that octet's corresponding character is outside the allowed set or is being used as a delimiter of, or within, the component. A percent-encoded octet is encoded as a character triplet, consisting of the percent character "%" followed by the two hexadecimal digits representing that octet's numeric value. For example, "%20" is the percent-encoding for the binary octet "00100000" (ABNF: %x20), which in US-ASCII corresponds to the space character (SP). Section 2.4 describes when percent-encoding and decoding is applied.

つまり、特殊記号は%に続けて2桁の16進数で表されます。この規則に則ると%は25`にエンコードされます。

ちなみにURLエンコーディングのの対象となる特殊記号はrfc3986 2.2よると以下です。

reserved = gen-delims / sub-delims
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?