Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection between docker containers via UNIX sockets

I’m newbie to Docker, but i’d like to know: is it possible to connect one container from another container on Linux machine (any) with UNIX sockets? For example i have one container for application core and second containers which covers database things. Second example is two containers with application code, and first container can trigger some events in second.

Performance really matters for me in both cases. If it’s impossible to do this way, is there is any solution for these problems?

Thanks!

like image 291
user2890234 Avatar asked Aug 11 '17 14:08

user2890234


Video Answer


1 Answers

Yes. You can mount a socket into a container using a volume mount. And multiple containers can mount the same volume, whether that's a named volume or a host mount, to share the socket between the containers. You see this frequently with containers that mount the docker socket today, e.g.

docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock busybox

will run a container with the docker socket mounted.


Notes on the docker.sock itself:

  1. The above is an example of mounting a socket, replace the docker.sock with the name of your own application's socket.
  2. Yes, the above gives the container access to manage docker, effectively root on the host. You see this with tools to manage docker packaged as containers. You are implicitly trusting them with root access on the server, not unlike trusting code downloaded with apt or rpm on the host. Be selective on what you give this access to.
like image 103
BMitch Avatar answered Oct 09 '22 16:10

BMitch