Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple containers that share same port #107

Open
hockeygoalie35 opened this issue May 11, 2024 · 1 comment
Open

Multiple containers that share same port #107

hockeygoalie35 opened this issue May 11, 2024 · 1 comment

Comments

@hockeygoalie35
Copy link

hockeygoalie35 commented May 11, 2024

Hi! Using your example docker compose with the reverse proxy works perfectly, but what happens if I want to use two containers that insist on using the same port? And worse, they both want to use port 80? Since I’m using networkmode: “service:vpn”, I can’t map the ports at a container level, only at the wireguard-PIA level. Any thoughts?

@thrnz
Copy link
Owner

thrnz commented May 13, 2024

If the two services are hardcoded to bind to port 80, then all I can think of would be running a second vpn container for the second service. They could still be attached to the same Docker bridge network if they need to communicate with each other, although it might be a bit fiddly as Docker's internal dns would no longer be used for resolving container names.

Something like this maybe:

services:
    vpn1:
        image: thrnz/docker-wireguard-pia
        volumes:
            - pia-dat:/pia
        ports:
            - 80:80
        cap_add:
            - NET_ADMIN
        environment:
            - LOCAL_NETWORK=192.168.1.0/24
            - LOC=swiss
            - USER=xxxx
            - PASS=xxxx
        sysctls:
            - net.ipv4.conf.all.src_valid_mark=1

    service1:
        image: some-docker-image
        network_mode: "service:vpn1"

    vpn2:
        image: thrnz/docker-wireguard-pia
        volumes:
            - pia-dat2:/pia
        ports:
            - 81:80
        cap_add:
            - NET_ADMIN
        environment:
            - LOCAL_NETWORK=192.168.1.0/24
            - LOC=swiss
            - USER=xxxx
            - PASS=xxxx
        sysctls:
            - net.ipv4.conf.all.src_valid_mark=1

    service2:
        image: some-docker-image
        network_mode: "service:vpn2"

volumes:
    pia-dat:
    pia-dat2:

Have you got an example compose showing what you're trying to do? If the issue isn't what I'm thinking of, then there might be an easier way of working around it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants