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

how to configure multiple domain (virtual host) and multiple virtual port #1463

Closed
jakata007 opened this issue Jun 29, 2020 · 5 comments · Fixed by #2434
Closed

how to configure multiple domain (virtual host) and multiple virtual port #1463

jakata007 opened this issue Jun 29, 2020 · 5 comments · Fixed by #2434
Labels
kind/feature-request Issue requesting a new feature scope/multiport Issue or PR related to multi port proxying

Comments

@jakata007
Copy link

I have run your image with command below.

docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro \
    --name my-nginx-proxy --network=mynetwork jwilder/nginx-proxy

my software run in single container and listen on port 81,82

  • port 81 designed for domain a.mydomain
  • port 82 designed for domain b.mydomain

case 1, I have use these command. It's work.

docker run -d --network=mynetwork -e VIRTUAL_PORT=81 -e VIRTUAL_HOST=a.mydomain myimage

case 2, I have use these command. It's work.

docker run -d --network=mynetwork -e VIRTUAL_PORT=82 -e VIRTUAL_HOST=b.mydomain myimage

Question, how to configure for the following situation?

I would like to use port 81 with domain a.mydomain and port 82 with domain b.mydomain in single container.

I have tried with the following command. It 's not work.
docker run -d --network=mynetwork -e VIRTUAL_PORT=81,82 -e VIRTUAL_HOST=a.mydomain,b.mydomain myimage

Please help.
Thanks you.

@tkw1536
Copy link
Collaborator

tkw1536 commented Jun 29, 2020

I don't think multiple services in the same container are supported at the moment.

A workaround might be to have "dummy" containers for each additional port, that do nothing but forward all connections to the second port.

@first087
Copy link

I don't think multiple services in the same container are supported at the moment.

A workaround might be to have "dummy" containers for each additional port, that do nothing but forward all connections to the second port.

I have the same problem for this issue.

My container run Nexus Repository in first port. It enable docker private repository in second port. I can't assign 2 domain by nexus-proxy.

Some app listen multiple port

Ex:

  • RabbitMQ listen second port for monitoring.
  • nginx listen 80, 443 for http and https

I think, one container running one service but listen single port is not always correct.

@jakata007
Copy link
Author

@jwilder please help.

@tkw1536
Copy link
Collaborator

tkw1536 commented Jul 1, 2020

@jakata007 @first087:
Here is a workaround until a new feature is implemented.

# start the nginx proxy
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro \
    --name my-nginx-proxy --network=mynetwork jwilder/nginx-proxy

# start the application container, take note that:
# - it is named (so that the proxies below can see it)
# - it does not have anything exposed
docker run -d --network=mynetwork --name myapp application-with-two-ports

# For each port that you want to expose, configure a pseudo container. 
# These only forward to the 'myapp' container above.
# They are additionally labeled for 'nginx-proxy' to pick up on. 
docker run -d --network=mynetwork -e VIRTUAL_PORT=80 -e VIRTUAL_HOST=a.mydomain \
    -e REMOTE_HOST=myapp -e REMOTE_PORT=81 marcnuri/port-forward
docker run -d --network=mynetwork -e VIRTUAL_PORT=80 -e VIRTUAL_HOST=b.mydomain \
    -e REMOTE_HOST=myapp -e REMOTE_PORT=82 marcnuri/port-forward

Disclaimer:
The image for proxying isn't mine, I haven't tested this.
If for some reason you don't trust random images, you can always build it from the Dockerfile or make your own image. It should contain something like:

CMD socat tcp-listen:$LOCAL_PORT,reuseaddr,fork tcp:$REMOTE_HOST:$REMOTE_PORT

Also, I doubt @jwilder is currently developing new features, see #1304 (comment).
So someone would have to make a PR and hope it gets merged.

@zahaim
Copy link

zahaim commented Aug 31, 2020

Many thanks for that workaround @tkw1536 , I was about to setup another registry / nexus just for 1 customer to achieve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature-request Issue requesting a new feature scope/multiport Issue or PR related to multi port proxying
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants