savez
12/7/2017 - 10:47 AM

Docker multi container and reverse proxy nginx

tutorial for using multiple docker container and proxy nginx for manage multiple project.

version: '2'

services:
  nginx-proxy:
    container_name: nginx-proxy
    image: jwilder/nginx-proxy
    network_mode: "bridge"
    ports:
      - "80:80"

    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

  mysql:
    container_name: mysql_global
    image: mysql:5.6
    network_mode: "bridge"
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_USER=default
      - MYSQL_DATABASE=default
      - MYSQL_PASSWORD=default

  portainer:
    container_name: portainer-global
    image: portainer/portainer
    ports:
      - "8001:9000"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Configuration

the file <docker-compose.yml> is principal file. Into file is set custom network for all containers with you wuold using with reverse proxy.

The <docker-compose.yml> start with some container:

  • mysql: for manfge all DBs of yours project (this is a solution for not use the TCP proxy)
  • portainer: this is a container for mange docker (access url: http://localhost:9000)

You can edit "network_mode" with the network that reverese proxy using.

Remember every container of the your project will have to use with the network of the reverse proxy.