mmdc
mmdc

Reputation: 1746

How to route traffic from one container to another in docker compose

I have this docker compose. I would like to route all traffic from app container through openvpn container without changing anything in host server. Is it possible?

version: '3'

services:
  openvpn:
    image: openvpn
    networks:
      - net

  app:
    image: myapp
    networks:
      - net

networks:
  net:
    driver: bridge

Upvotes: 2

Views: 3416

Answers (1)

mmdc
mmdc

Reputation: 1746

I found it by myself. I can add myapp to the same network of openvpn by adding a config to myapp service.

network_mode: "service:openvpn"

By this, I cannot expose the port on myapp but I can expose ports in openvpn to access myapp as they are in the same network

Upvotes: 3

Related Questions