1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

dockerfileに記述せずdocker buildプロキシ設定まとめ

Posted at
 ubuntu20.04 
# dockerd に環境変数でプロキシ設定
$sudo systemctl edit docker
[Service]
Environment="HTTP_PROXY=http://user:pw@xxx:8080"
Environment="HTTPS_PROXY=http://user:pw@xxx:8080"
Environment="NO_PROXY=xxx"

# vi /etc/systemd/system/docker.service(/etc/systemd/system/docker.service.d/override.confもしかしたらこちらの可能性あり)
[Service]
Environment="HTTP_PROXY=http://user:pw@xxx:8080"
Environment="HTTPS_PROXY=http://user:pw@xxx:8080"
Environment="NO_PROXY=xxx"
Environment="DOCKER_NETWORK_OPTIONS=--dns xxx"
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_NETWORK_OPTIONS
dnsはnslookupで取得したものを入れる

# ~/.docker/config.json作成(大抵ユーザディレクトリ内に.dockerディレクトリ存在)
{
  "proxies": {
    "default": {
      "httpProxy": "http://user:pw@xxx:8080",
      "httpsProxy": "http://user:pw@xxx:8080",
      "noProxy": "xxx"
    }
  }
}

# デフォルトの設定
$vi /etc/default/docker
export http_proxy="http://user:pw@xxx:8080"
export https_proxy="http://user:pw@xxx:8080"
export no_proxy="xxx"
export NO_PROXY="${no_proxy}"
export HTTP_PROXY="${http_proxy}"
export HTTPS_PROXY="${https_proxy}"

# apt のプロキシ設定
$ nano /etc/apt/apt.conf
Acquire::http::Proxy "http://user:pw@xxx:8080";
Acquire::https::Proxy "http://user:pw@xxx:8080";

# Dockerデーモンにプロキシ設定
$ mkdir -p /etc/systemd/system/docker.service.d
$ vi /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://user:pw@xxx:8080"
Environment="HTTPS_PROXY=http://user:pw@xxx:8080"
Environment="NO_PROXY=xxx"
Environment="DOCKER_NETWORK_OPTIONS=--dns xxx"
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_NETWORK_OPTIONS

# 状態確認
$systemctl status docker.service

# 再起動
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

# ビルド
docker build --build-arg http_proxy=http://user:pw@xxx:8080 --build-arg https_proxy=http://user:pw@xxx:8080 .

蛇足:
ECRにプッシュ方法:
・AWSでコードパイプラインを使用して、dockerfileからビルド~プッシュをして、ECRリポジトリにプッシュする方法
・プッシュコマンドを利用してECRリポジトリにプッシュする方法
1番目の方法でプッシュする環境なのに、で2番目の方法でECRにプッシュして、プロキシエラーが出て、認識抜けでdockerプロキシ設定してしまった。環境ができていたので、そのままgit コミットでcodecommitが動きECRプッシュしてくれていた。。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?