Giter Site home page Giter Site logo

docker-reverse-proxy-example's Introduction

Docker swarm reverse proxy example with nginx

This solution uses the automated nginx proxy from jwilder/proxy. The point is that in Portainer i made separate stacks for the proxy and the application(s).

Test environment:

  • Ubuntu 16.04 LTS
  • Docker version 17.05.0-ce, build 89658be
  • Swarm mode with single node

The network

The key to the solution is a common network you have to define in the Networks section of Portainer.

Name proxy
Driver overlay
Scope swarm
Attachable false
Internal false
Subnet 10.0.0.0/24
Gateway 10.0.0.1

The corresponding docker command is (not tested):

docker network create --driver overlay --attachable proxy

The proxy stack

The proxy stack is created with docker-compose-proxy.yml file. Contains a single proxy container based on jwilder/nginx-proxy image.

version: '3'
services:
  proxy:
    image: jwilder/nginx-proxy
    ports:
      - 80:80
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
    networks:
      - proxy
networks:
  proxy:
    external: true

The application stack

The application stack is created with docker-compose-app.yml file. The example contains a single test application using jwilder/whoami image.

version: '3'
services:
  whoami:
    image: jwilder/whoami
    environment:
      - VIRTUAL_HOST=whoami.yourdomain
    ports:
      - 8098:8000
    networks:
      - app     # if more than one container exists, must be added to all containers
      - proxy   # add only to the web container
networks:
  app:
  proxy:
    external: true

If the application stack has other containers, e.g. 'db', it also have to connected to the network 'proxy' or an other common network with the main application container.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.