I want to setup serve multiple sites from one server:

1. http://www.example.org => node.js-www (running on port (50000)
2. http://files.example.org => node.js-files (running on port 50001)

Until now I only found out to have docker doing port redirect when using static ips.

Is is actual possible to use docker for port redirection via hostname?

I use a free amazon EC2 insance.

Thanks Bo

EDIT: I want to have multiple nodes applications running on the same port but however serving a different hostname.

有帮助吗?

解决方案

As far as I'm aware docker does not have such functionality built in, nor it should. To accomplish what you're trying to do you'd probably need some sort of reverse proxy, so node.js or nginx would do. Bouncy might be a good option: https://github.com/substack/bouncy

其他提示

There is a great docker project on GitHub called nginx-proxy by jwilder. This allows you to create a docker container that is doing a reverse-proxy by mapping only his port 80/443 to the host, instead of other containers. Then, all you have to do is for every new web container you create, provide a new environment variable VIRTUAL_HOST=some.domain.com.

An example:

  1. Create a new nginx-proxy container

    docker run -d -p 80:80 --net shared_hosting -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
    
  2. Create a container for each website. For example:

    docker run -d -p 80 --net shared_hosting -e VIRTUAL_HOST=hello1.domain.com tutum/hello-world
    docker run -d -p 80 --net shared_hosting -e VIRTUAL_HOST=drupal.domain.com drupal
    
  3. You need to make sure that the hosts you own, configured in DNS to point to the server that runs the docker container. In this example, I will add the to the /etc/hosts file:

    echo "127.0.0.1 hello1.domain.com drupal.domain.com" >> /etc/hosts
    
  4. Navigate to http://hello1.domain.com and then to http://drupal.domain.com, and see that they both use port 80 but give you a different pages.

An important note about this service. As you noticed, I have added --net argument, this is because all containers you want to be a part of a shared hosting (proxy and websites) must be on the same virtual network (this can be defined by the argument --net or --network to the docker run command), especially when you use docker-compose to create dockers, because docker-compose creates its own virtual network, thus makes one container not reachable by another, so make sure the network is explicitly defined in the docker-compose.yml file.

Hope it helps.

I used varnish as a docker container that worked as my reverse proxy

it's on the docker index

https://index.docker.io/u/sysdia/docker-varnish/

I know this is an old question, but ran across it and wanted to point out that there are much cleaner ways to do what was requested. Since you are using AWS, you can have each of your two hostnames pointing at their own load balancer (ELB) in Route53. You could then deploy your container into ECS, for example, listening on both ports. Each of those load balancers can redirect traffic to the appropriate listening port. Now you have accomplished what you want, and if your traffic becomes too heavy or imbalanced, you can easily split the tasks into two different ECS clusters so they can scale independently.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top