0
0

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 3 years have passed since last update.

RHEL 7.6にDocker環境を作る w/ 社内プロキシやCA証明書

Last updated at Posted at 2021-04-15
Page 1 of 13

はじめに

社内プロジェクトでDockerを使いたいけどプロキシやら社内CA証明書やら設定しなきゃ...というのを毎回調べるのが面倒になるので手順をメモ。


手順


Subscription manager への登録

参考: RedHat Customer Portal - Subscription Management コマンドを使用する

# 色んなパターンがあるので適切な方法で。
sudo subscription-manager register --username=yourusername --password=yourpassword
sudo subscription-manager register --activationkey=hogehoge --org=fugafuga --proxy=http://inhouse.proxy.example.com:8080

追加yumリポジトリの有効化

参考: RedHat Customer Portal - リポジトリを有効にする

sudo subscription-manager repos --enable=rhel-7-server-extras-rpms

Dockerのインストール

sudo yum install docker -y

入るバージョンが結構古いので注意。最新版を入れたければ公式ガイドの手順に従うのが無難。
Install Docker Engine on CentOS


Dockerへの環境変数(プロキシ関係)の設定

sudo systemctl edit docker

viが起動するのでプロキシ関係の設定を次のように追加

[Service]
Environment=http_proxy=http://inhouse.proxy.example.com:8080
Environment=https_proxy=http://inhouse.proxy.example.com:8080
Environment=HTTP_PROXY=http://inhouse.proxy.example.com:8080
Environment=HTTPS_PROXY=http://inhouse.proxy.example.com:8080

大文字小文字のどっちの変数名を見てるかわからなかったので、とりあえず両方設定。多分片方だけでいい。


(オプション)dockerコマンドをsudoなしで使えるようにする

ユーザをdockerグループに追加するとできるようになる。
参考: Manage Docker as a non-root user

sudo groupadd docker
sudo usermod -aG docker some-user

実行後にユーザの再ログインがいるかも。


CA証明書のインストール

CA証明書ファイルをsomeCert.crtとするとこんな感じ。
参考: RedHat Customer Portal - 4.14. 共有システムの証明書の使用

sudo cp someCert.crt /etc/pki/ca-trust/source/anchors/
sudo update-ca-trust extract

上記は全リポジトリ(というかRHEL全体)で有効なCA証明書になる。特定のリポジトリのみに必要なCA証明書なら次のページを参考に設定を。


Dockerの起動

sudo systemctl start docker
sudo systemctl enable docker

Dockerの動作確認

docker run --rm hello-world
  • --rmオプションつけておくと停止後にコンテナが自動で消える。動作確認後はどうせ不要なコンテナなのでつけておくと吉。

(オプション) プライベートレジストリにHTTP接続できるようにしておく

デフォルトではレジストリへの接続はHTTPSになるが、社内リポジトリはオレオレ証明書などで設定が面倒だったりするのでHTTPで接続できるようにしてしまう。


お疲れさまでした

多分これで動くと思いますが、なんかおかしなことしてたらマサカリください。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?