dockeralpine-linuxmpdportainermopidy

How do I access Mopidy running in Docker container from another container


To start, I am more familiar running Docker through Portainer than I am with doing it through the console.

What I'm Doing:

Currently, I'm running Mopidy through a container, which is being accessed by other machines through the default Mopidy port. In another container, I am running a Slack bot using the Limbo repo as a base. Both of them are running on Alpine Linux.

What I Need:

What I want to do is for my Slack bot to be able to call MPC commands, such as muting the volume, etc. This is where I am stuck. What is the best way for this to work

What I've tried:

I could ssh into the other container to send a command, but it doesn't make sense to do this since they're both running on the same server machine.


Solution

  • The best way to connect a bunch of containers is to define a service stack using docker-compose.yml file and launch all of them using docker-compose up. This way all the containers will be connected via single user-defined bridge network which will make all their ports accessible to each other without you explicitly publishing them. It will also allow the containers to discover each other by the service name via DNS-resolution.

    Example of docker-compose.yml:

    version: "3"
    services:
      service1:
        image: image1
        ports:
          # the following only necessary to access port from host machine
          - "host_port:container_port"
      service2:
        image: image2
    

    In the above example any application in the service2 container can reach some port on service1 just by using service2:port address.