0

I am completely new to Docker and don't really understand how "link" works between containers. I wrote a little java-program with some packages and I want each package to run on a different container. I would like the packages to find each other through the link and communicate with each other. The goal is, that when I execute the main class in my main container, that this class finds all the other packages in the other containers and can use them. It works without a problem when I use volumes but I would like to know if I can do it just with links and ports and without having to use volumes.

I imagine this being a very stupid question but I read everything here: https://docs.docker.com/userguide/dockerlinks/ but still don't understand how it really works.

Could someone help me with it?

Plasmaschnee
  • 57
  • 1
  • 2
  • 11
  • Packages and specifically classes are a Java construct that is internal to a JVM. As far as Docker is concerned the JVM is just another Linux process, so linking containers together is more akin to running two Java programs on the same server. – Mark O'Connor Oct 27 '15 at 21:15
  • Ah ok that is kind of what I thought it was doing. So if I still want to run every package on a different container and I want them to work together I will have to use data volumes – Plasmaschnee Oct 28 '15 at 07:47
  • Would be more sensible to share jars using a Maven repository then build and run each container separately. For an example see: http://stackoverflow.com/questions/31696439/how-to-build-a-docker-container-for-a-java-app/31710204#31710204 – Mark O'Connor Oct 28 '15 at 08:31
  • Thank you very much! I don't know much about Maven but I will try it that way. So just to make it clear: links can connect two services as long as they are services who can run separately like for example a data base and a service who uses data from the data base. So when I link them together the one service can get data from the other one. But I can not take one service, split it in two and run every half in a container and connect them both via link. – Plasmaschnee Oct 28 '15 at 10:47
  • Yup that's about the size of it. And linking provides some additional benefits such as setting environment variable and altering host files so that the container being linked to can be easily found by the other (port number and IP address) – Mark O'Connor Oct 28 '15 at 20:34
  • Alright! Thank you very much for your help! :) – Plasmaschnee Oct 29 '15 at 11:30

0 Answers0