GNU/Linux >> Linux の 問題 >  >> Ubuntu

Ubuntu上のDockerコンテナのTraefik

この投稿は、Dockerコンテナ用のTraefikに関するものです。

構成の概要

魔法がどうなるか

DockerコンテナのTraefik

Dockerをまだインストールしていない場合は、UbuntuまたはDebianの手順を見つけることができます。このガイドでは、docker-composeを使用してTraefikを実行するため、docker-composeもインストールする必要があります。リンクされた2つのガイドは、独自のホストでdocker-composeをセットアップするのに役立ちます。

Traefikの設定から始めましょう。

まず、コンテナ用のファイルとフォルダディレクトリをいくつか作成します。

mkdir -p /opt/containers/traefik
mkdir /opt/containers/traefik/data
touch /opt/containers/traefik/data/traefik.yml
touch /opt/containers/traefik/data/acme.json
chmod 600 /opt/containers/traefik/data/acme.json
安全なパスワードを生成

構成ファイルを作成し、暗号化されたパスワードを設定して、traefikダッシュボードにアクセスします。 htpasswdユーティリティを使用して、暗号化されたパスワードを作成できます。 htpasswdユーティリティを使用するには、次のコマンドでユーティリティをインストールします

$ sudo apt-get install -y apache2-utils

次に、次のコマンドを実行して安全なパスワードを生成します

$sudo htpasswd -nb unixcop unixcop@123
unixcop:$$apr1$$zUb/YuK2$$57psQ0U71DlfdHPr0yoHe/

暗号化には「unixcop@123」を使用しました。あなたはあなた自身の仮定を持つことができます。ユーザーは「unixcop」と見なされ、自分のユーザー名に置き換えることができます。

自動生成された出力をコピーして、Traefikダッシュボードの基本認証をセットアップするためにTraefik構成ファイルでこの暗号化されたパスワードを使用する必要があるため、どこかに保存します

traefik.yml

次に、新しく作成したtraefik構成ファイルを選択したエディターで開きます。

vim /opt/containers/traefik/data/traefik.yml
api:
  dashboard: true
entryPoints:
  http:
    address: ":80"
  https:
    address: ":443"
providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
certificatesResolvers:
  http:
    acme:
      email: [email protected]   # CHANGE HERE
      storage: acme.json
      httpChallenge:
        entryPoint: http

docker-compose.ymlを作成します reverse-proxyを定義するファイル 公式のTraefik画像を使用するサービス:

docker-compose.yml

version: '3'
services:
  traefik:
    image: traefik:latest
    container_name: traefik
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    networks:
      - proxy
    ports:
      - 80:80
      - 443:443
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./data/traefik.yml:/traefik.yml:ro
      - ./data/acme.json:/acme.json
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.entrypoints=http"
      - "traefik.http.routers.traefik.rule=Host(`traefik.domain.tld`)"
      - "traefik.http.middlewares.traefik-auth.basicauth.users=unixcop:$$apr1$$zUb/YuK2$$57psQ0U71DlfdHPr0yoHe"
      - "traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.traefik.middlewares=traefik-https-redirect"
      - "traefik.http.routers.traefik-secure.entrypoints=https"
      - "traefik.http.routers.traefik-secure.rule=Host(`traefik.domain.tld`)"
      - "traefik.http.routers.traefik-secure.middlewares=traefik-auth"
      - "traefik.http.routers.traefik-secure.tls=true"
      - "traefik.http.routers.traefik-secure.tls.certresolver=http"
      - "traefik.http.routers.traefik-secure.service=api@internal"
networks:
  proxy:
    external: true

docker-compose.ymlを使用して、すべての設定ファイルと構成ファイルを使用してTraefikdockerコンテナーを定義しています。 Traefikを起動して実行するには、いくつかの設定を調整するだけです。

  • 両方のtraefik.domain.tldを置き換えます あなた自身のドメイン名で。このドメインは、たとえばtraefik.ae3.chのようなサブドメインである必要があります。後で、この(サブ)ドメインを使用してTraefikDasboardにアクセスできるようになります。

Traefik用のDockerネットワークを作成する

Traefikで使用される別のDockerネットワークと、Traefikで利用できるようにする他のすべてのDockerコンテナを設定することをお勧めします。

このDockerネットワークを作成するには、次のコマンドをCLIに貼り付けるだけです。

docker network create proxy

Traefikを実行

docker-compose up -d

数秒後、docker-compose.ymlに入力したカスタムドメインでTraefikダッシュボードを確認してアクセスできます


Ubuntu
  1. UbuntuのFirefox「クローン」?

  2. Ubuntu 20.04でのDockerの問題?

  3. CcleanerはUbuntuにとって有益ですか?

  1. Virtualbox 5.1.2 for Ubuntu 14.04.5?

  2. Ubuntu14.04のApt-fast??

  3. UbuntuでDockerをインストールしてDockerコンテナを実行する方法

  1. UbuntuのAlexa?

  2. Docker

  3. Dockerのインストール(Ubuntu)