Multi-container ASP.NET 5 apps with Nginx and Redis

Sign in to queue

The Discussion

  • User profile image
    Thiago Custodio

    Can I link the two containers directly through DockerFile?

  • User profile image
    beverts

    @Thiago Custodio: You cannot link two containers using a Dockerfile because a dockerfile is used to represent an Image (not a single container or group of containers). However, we can use a file to define a set of containers though using Docker compose (https://docs.docker.com/compose/yml/#links) .

  • User profile image
    shawn

    for the Nginx demo, what about if we need to load balance to containers run in different VMs, is there a native way to register those services to a registry which Nginx config can refer? thanks!

  • User profile image
    Dan

    Hey Shawn, 

    Short answer is yes, but there's lots of ways to do it.

    Nginx

    While my example was simple to keep the concept count low, the next step you would do is make the Nginx configuration file to be volume mounted so that way you can write (add/update) new entries that could be containers on separate VMs.

    Again, there are many ways to do this. One way is to listen to Docker for when a container has been created or destroyed. To do that, you can listen to docker events, like if a new container is spun up, it's added to the load balancer.

    That works great on a single VM by default. To have it work across multiple VMs, you can use Docker Swarm. Docker Swarm allows you to add, say three VMs into one logical VM. More info on Swarm can be found here. The nice thing about Swarm is you can use the exact same commands, like the Docker events to get information on state changes for containers across multiple VMs.

    So back to our example, setup 3 VMs using Docker Swarm, choose one of those to run Nginx with a volume mounted config file, listen to Docker events and add/update the config file based on what containers are running on what machines.

    Each clustering/orchestration tool will have their own answer for this as well, so again this is one of many solutions. 

     

    Hope this helps. 

    -Dan

  • User profile image
    bxmbi

    who is this

  • User profile image
    bxmbi

    Can I link the two containers directly through DockerFile?

    get my brother out. I thought it was him . I saw him in prison orange.

  • User profile image
    bxmbi

    @shawn:get him out and make sure they leave for the airport

  • User profile image
    bxmbi

    thank you channel 9

Add Your 2 Cents