Docker Linking in C # is the best way to expose environment variables injected by linking

So, I am creating a simple application with multiple containers in C # with the following article Dockerization of a Redis Service

I created my Redis image using the following Dockerfile:

FROM        ubuntu:14.04
RUN         apt-get update && apt-get install -y redis-server
EXPOSE      6379
ENTRYPOINT  ["/usr/bin/redis-server"]

      

then i create my image using the following command

docker build -t sample/redis

and finally created my Redis container

docker run -d --name redis sample/redis

Then I create a web application container that runs a simple console application to run Redis

using the following Dockerfile

FROM ubuntu:14.04

EXPOSE 1234

ENTRYPOINT ["mono","/path/to/my/app/app.exe"]

      

Using this Dockerfile I have built an image ...

docker build -t sample/my-app-image

and finally I created a container with a link to the container I created earlier Redis

.

docker run --link redis:redis --name my-app-image -d -it sample/my-app-image

and my application looks something like this:

public class Program
{  
   public static void Main(string[] args)
   {
        var path = Environment.GetEnvironmentVariable("REDIT_PORT_6379_TCP_ADDR");
        IRedisCache cache = new RedisCache(path);
   }
}

      

Is it being used correctly Environment.GetEnvironmentVariable(...)

to grab related information from a Redis container, or am I doing it completely wrong?

var path = Environment.GetEnvironmentVariable("REDIT_PORT_6379_TCP_ADDR");

      

It doesn't seem like a very custom approach. Any suggestions or modifications I should be doing?

+3


source to share





All Articles