Docker Community Forums

Share and learn in the Docker community.

Network issue: accessing external servers from containers on subnets

0

I have a container with 2 subnets:

one is the reverse proxy subnet
the second one is the internal subnet for the different containers of that project

The container needs to access an external SMTP server (on mailgun.com), but it looks like, with docker-compose, you can put a container on both one or more subnets and give it access to the host network at the same time.

Is there a way to allow this container to initiate connections to the outside world?

and, if no, what common workarounds are used? (for example, adding an extra IP to the container to be on the host network, etc.)

I can only imagine that the scenario of having several containers on a private network and one of them needing to talk to the outside to be common.

This is the docker compose file:

version: '2.3'

services:

  keycloak:
    container_name: keycloak
    image: jboss/keycloak
    restart: unless-stopped
    volumes:
      - '/appdata/keycloak:/opt/jboss/keycloak/standalone/data'
    expose:
      - 8080
    external_links:
      - auth
    networks:
      - default
      - nginx
    environment:
      KEYCLOAK_USER: XXXX
      KEYCLOAK_PASSWORD: XXXX
      PROXY_ADDRESS_FORWARDING: 'true'
      ES_JAVA_OPTS: '-Xms512m -Xmx512m'
      VIRTUAL_HOST: auth.XXXX.com
      VIRTUAL_PORT: 80
      LETSENCRYPT_HOST: auth.XXXX.com
      LETSENTRYPT_EMAIL: admin@XXXX.com

networks:
  default:
    external:
      name: app-network
  nginx:
    external:
      name: nginx-proxy