blacklabelops
blacklabelops

Reputation: 4948

Docker Container to Host Routing

I need a better up-to-date solution the following problem:

Problem: I have to manually create an iptable rule in order to allow a route from a dynamically docker bridge to the host. Otherwise container a cannot connect to container b because there is by default no route from a docker network to the docker host itself.

I have the following setup:

container-nginx (docker)
|
|-container-jira (docker) (https://jira.example.com)
|-container-confluence (docker) (https://confluence.example.com)

In order to have properly functioning Atlassian application links between Jira and Confluence:

I use docker-compose for the whole setup and all container are inside the same network. By default this will not work i will get "no route to host" in both containers for hosts confluence.example.com and jira.example.com. Because every container inside the docker network have no route to the docker host itself.

Currently, each time the setup is initialized I manually create an iptable rule from the dynamically created docker bridge with id "br-wejfiweji" to the host.

This is cumbersome, is there "a new way" or "better way" to do this in Docker 1.11.x?

Upvotes: 1

Views: 2863

Answers (1)

VonC
VonC

Reputation: 1323115

docker-compose version 2 does create a network which allows all containers to see each other. See "Networking in Compose" (since docker 1.10)

If your containers are created with the right hostname, that is jira.example.com and confluence.example.com (see docker-compose.yml hostname directive), nginx can proxy-pass directly to jira.example.com and confluence.example.com.
Those two hostname will resolve to the right IP address within the network created by docker-compose for those 3 (nginx, jira and confluence) containers.

I suggest in the comment to use an alias in order for jira to see confluence as nginx (nginx being aliases to confluence), in order for jira to always use nginx when accessing confluence.

version: '2'

services:
  # HTTPS-ReverseProxy
  nginx:
    image: blacklabelops/nginx
    container_name: nginx
    networks:
      default:
        aliases:
          - 'crucible.example.com'
          - 'confluence.example.com'
          - 'crowd.example.com'
          - 'bitbucket.example.com'
          - 'jira.example.com'
    ports:
      - '443:443'

Upvotes: 1

Related Questions