It is currently Wed Jun 16, 2021 9:49 am
All times are UTC + 8 hours

Deploy container to use Host database

Portainer is a lightweight management UI which allows you to easily manage your Docker host or Swarm cluster.

Deploy container to use Host database

Postby krunchynug8 » Mon Jun 15, 2020 11:56 am

Hi folks. I want to know how to get a docker container to access and use the host's MariaDB database?
For example a container like NextCloud using MariaDB of Host DB.
I have been trying to do this without much success.

I found that in Windows we can connect to the host simply using host.docker.internal.
However this does not work for me. Do I simply use the host local IP with Bridge network driver? or Host network driver?
Portainer has these fields for Network settings of a container while deploying -
Annotation 2020-06-15 132109.jpg
Annotation 2020-06-15 132109.jpg (94.84 KiB) Viewed 765 times
- could you give me examples of what these will be for me to connect to the host database?

Does the host database user require any special permissions?
Thanks
krunchynug8
 
Posts: 12
Joined: Thu May 28, 2020 1:30 pm

Re: Deploy container to use Host database

Postby Nazar78 » Thu Jun 18, 2020 11:40 am

You can connect using two methods, TCP or Unix socket (I prefer this).

TCP:
Find out your host docker IP, use "ipconfig" command look for docker0 or at the Portainer's "Networks" bridge section, e.g. 172.17.0.1 so your client would connect to host's MySQL 172.17.0.1:3306. Issue here is that you'll not be able to connect if the host MySQL is set to bind to local-only 127.0.0.1 unless you change the host's MySQL config bind to 0.0.0.0. You can quickly check if this is local-only binding by using your laptop/PC or even the NAS itself try to connect (mysql client or telnet) on the same sub net i.e. 192.168.x.x:3306, or using command "netstat -natp|grep :3306". If the connection timed out or you see 127.0.0.1:3306 then your host MySQL is only listening to local connections, hence changes to the host's MySQL cnf is needed.

Socket:
Configure the NextCloud container to bind and use your host's MySQL Unix socket. Recreate your NextCloud container, can be done easily from Portainer itself, under Containers->NextCloud->Duplicate/Edit->Volumes->map additional volume. Bind the container's /run/mysqld/mysqld.sock with host's /run/mysqld/mysqld.sock. Make sure you click the "Bind" by default it's "Volume". Reconfirm your host socket path using command "netstat -na|grep mysql" as I remembered it's a bit different last time I use (now I'm using MariaDB in chroot) . Click "Deploy the container" and accept any warning prompts. Then configure NextCloud to use 127.0.0.1:/run/mysqld/mysqld.sock.
AS5304T - 16GB DDR4 - [40TB N300 RAID10 + 5 Bay USB: 8TB RAID5 & 480GB SSD for Apps]
User avatar
Nazar78
 
Posts: 294
Joined: Wed Jul 17, 2019 10:21 pm
Location: Singapore

Return to Portainer

  • You cannot post new topics in this forum
    You cannot reply to topics in this forum
    You cannot edit your posts in this forum
    You cannot delete your posts in this forum
    You cannot post attachments in this forum
  • Who is online

    Users browsing this forum: No registered users and 1 guest