Skip to content

Instantly share code, notes, and snippets.

@hmldd
Last active October 30, 2019 06:49
Show Gist options
  • Select an option

  • Save hmldd/53b01d6ae4d39b81c9267a7d9e1cf818 to your computer and use it in GitHub Desktop.

Select an option

Save hmldd/53b01d6ae4d39b81c9267a7d9e1cf818 to your computer and use it in GitHub Desktop.

Revisions

  1. hmldd revised this gist Oct 30, 2019. 3 changed files with 25 additions and 5 deletions.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,6 @@ whoami地址:http://whoami.docker.localhost

    web UI地址:http://localhost:8080

    traefik API原始数据地址:http://localhost:8080/api/rawdata
    traefik API原始数据地址:http://localhost:8080/api/rawdata

    Nginx地址:http://web.docker.localhost
    20 changes: 16 additions & 4 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    version: '3'

    services:
    proxy:
    gateway:
    # 官方最新的 traefik docker 镜像
    image: traefik:latest
    # 停止后重新启动
    restart: unless-stopped
    # 开启 traefik web UI 界面并监听 docker
    command:
    command:
    - --api.insecure=true
    - --providers.docker
    ports:
    @@ -19,7 +19,19 @@ services:
    # 绑定 docker.sock 使 traefik 能够监听 docker 事件
    - /var/run/docker.sock:/var/run/docker.sock
    whoami:
    # 通过 IP 地址或域名提供一个容器的服务
    image: containous/whoami
    # 通过 IP 地址或域名提供一个容器的服务
    labels:
    - "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"
    nginx:
    image: nginx:latest
    restart: unless-stopped
    # 绑定 web 文件目录和 nginx 配置目录
    volumes:
    - ./web:/web:ro
    - ./config/nginx/vhost.conf:/etc/nginx/conf.d/vhost.conf
    # 解决 docker 容器中的 bash 前台执行外部命令时不接收 signal 的问题
    command: "/bin/sh -c 'while :; do sleep 6h; nginx -s reload; done & exec nginx -g \"daemon off;\"'"
    # 通过 IP 地址或域名访问
    labels:
    - "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"
    - "traefik.http.routers.nginx.rule=Host(`web.docker.localhost`)"
    6 changes: 6 additions & 0 deletions vhost.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    # Nginx静态文件服务器配置
    server {
    server_name web.docker.localhost;

    root /web;
    }
  2. hmldd revised this gist Oct 30, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    启动:`docker-compose up -d`

    启动两个whoami实例:`docker-compose up -d --scale whoami=2`

    whoami地址:http://whoami.docker.localhost

    web UI地址:http://localhost:8080

    traefik API原始数据地址:http://localhost:8080/api/rawdata
  3. hmldd created this gist Oct 30, 2019.
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    启动:`docker-compose up -d`
    启动两个whoami实例:`docker-compose up -d --scale whoami=2`

    whoami地址:http://whoami.docker.localhost
    web UI地址:http://localhost:8080
    traefik API原始数据地址:http://localhost:8080/api/rawdata
    25 changes: 25 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    version: '3'

    services:
    proxy:
    # 官方最新的 traefik docker 镜像
    image: traefik:latest
    # 停止后重新启动
    restart: unless-stopped
    # 开启 traefik web UI 界面并监听 docker
    command:
    - --api.insecure=true
    - --providers.docker
    ports:
    # HTTP 端口
    - "80:80"
    # Web UI 端口(通过 --api.insecure=true 开启)
    - "8080:8080"
    volumes:
    # 绑定 docker.sock 使 traefik 能够监听 docker 事件
    - /var/run/docker.sock:/var/run/docker.sock
    whoami:
    # 通过 IP 地址或域名提供一个容器的服务
    image: containous/whoami
    labels:
    - "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"