• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question Networking between Docker containers

davorg

Basic Pleskian
I've been experimenting with Docker. I have an application that is made up of two Docker containers - one has a Perl web application and the other has a MariaDB database.

I've installed both containers using the Plesk Docker extension and I can get them both up and running. I've mapped the MariaDB container's port to 13306 and I can successfully connect to the database from the command line. I've mapped the web application's port to 1702 and I can see the application running on that port, but it only ever throws errors - because it can't connect to the database. I've tried setting the DB host to both "localhost" and "127.0.0.1" and in both cases I get connection errors in the logs.
DBI Connection failed: DBI connect('host=localhost;database=succession;port=13306','succession',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /succession/local/lib/perl5/DBIx/Class/Storage/DBI.pm line 1517.
On my laptop, I have this working successfully, but I had to add --network="host" to the docker run command in order to get it to work. How do I get host networking working on Docker containers running under Plesk?

Alternatively, I have a Docker compose definition that runs successfully, but I can't see any way to run docker-compose under Plesk. Am I missing something obvious?

Thanks for your help.

Dave...
 
Hello, you need to use ip other then localhost or 127.0.0.1. You can't use there IPs because mysql clients routes this requests to local socket and you can not change this (and there are no mysql socket inside your perl container). You can share socket between containers using volumes but i could not suggest this method. Just use your server public ip and port.
You can use docker-compose on plesk server, but it is not supported natively by docker extension yet. So, you need to install docker-compose using this manual Install Docker Compose. Then you can setup internal networking using docker-compose (not exposing mysql port outside, but only for perl internally) and proxy requests from web to perl container using nginx additional server rules. But this method a bit more complicated then first one.
 
Thanks. That makes sense, I guess. But I'd like it more if the Docker extension supported the various inter-containing networking modes that "docker build" supports.

I might look at installing docker-compose. But I think it's more likely that I'll try running this on AWS ECS instead.

Dave...
 
Back
Top