How to use Docker links to *safely* connect from a Virgo application to a MongoDB
Some months ago, the Docker Team announced Docker 0.6.5. Since that release it is possible to give your container names – this makes it much easier to find the correct container to interact with. It didn’t take long that I got used to this new feature.
Together with the freshly introduced explicit linking this is a huge security improvement.
Links allow containers to discover and securely communicate with each other by using the flag
Setting the new Docker daemon flag
-icc=false disallows inter-container communication, if needed.
Let’s give it a try and create an explicit link from an application running inside a Virgo container to a MongoDB running in another container.
$ docker run -name mongodb -t eclipsesource/mongodb $ docker run -link mongodb:db -name virgo -t eclipsesource/virgo-spring-325
Docker will provide some environment variables within the linked container:
Those variable names are built from the exported port of the container mongodb and the second part of the link option given when starting the Virgo container.
For more information about linking please consult the Docker documentation section “Link Containers”.
Within the Virgo application you can access the environment variables when creating the MongoDB factory:
The snippet above uses the defaults declared in
mongodb.properties when no environment variables are present.