mariaDB docker container inside LXD isn't accessible from the host OS

Hello everyone.
I have an LXD container and i have installed docker inside the LXD container as described here
(Running Docker inside of a LXD container - YouTube)
Inside the LXD container i have deployED a mariaDB instance from the offical docker repo.
I ran the docker container with the -p option in order for the docker container to be accessible from processes outside the LXD container.

I have a python script at the host OS which tries to connect to the mariaDB container but i receive:

ERROR:root:2003 (HY000): Can’t connect to MySQL server on ‘’ (111)

which indicates that the network connection has been refused.

I ran tcpdump inside the LXD container and the traffic arrives normally at port 3306 which is the mariadb’s default port.

ip a gives the following:

root@batterystation:/home/ubuntu# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:3e:06:dd:5a brd ff:ff:ff:ff:ff:ff
    inet brd scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:3eff:fe06:dd5a/64 scope link 
       valid_lft forever preferred_lft forever
8: eth0@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:bd:6d:3a brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet brd scope global dynamic eth0
       valid_lft 2628sec preferred_lft 2628sec
    inet6 fe80::216:3eff:febd:6d3a/64 scope link 
       valid_lft forever preferred_lft forever

while ip r gives

root@batterystation:/home/ubuntu# ip r
default via dev eth0 proto dhcp src metric 100 dev eth0 proto kernel scope link src dev eth0 proto dhcp scope link src metric 100 dev docker0 proto kernel scope link src linkdown

Any help ?

I tried the examaple with the nextcloud docker container inside the demo lxd container and worked fine by the way.

I find this → LXD , docker , mariadb/mysql - #5 by benoit.georgelin

So it means we hit a wall, right ?

No XP - I might be wrong - tried adding a proxy device / making sure mariadb listens on every interface?

I cant imagine docker mariadb listens on every network interface by default, most DB dont these days…


It does actually

root@batterystation:/# docker ps
CONTAINER ID   IMAGE        COMMAND                  CREATED          STATUS         PORTS                                       NAMES
c36722cca4a8   bsdb_image   "docker-entrypoint.s…"   10 seconds ago   Up 4 seconds>3306/tcp, :::3306->3306/tcp   bsdb

The bsdb_image isn’t something special. It is the official mariadb image plus a .sql configuration which just simple create some tables

Hi @tkasidakis ,
I have tested an example and reached mariadb server from host my machine, here are my steps.

lxc launch images:ubuntu/22.04/cloud test
lxc config set test security.nesting=true
lxc shell test
apt install curl
curl -ssl | sh
systemctl start docker
docker run --name mariatest -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123qwe -d mariadb

At the host side, installed the apt install mariadb-client-core-10.6 maria client.
And connect with the following statement.

mariadb --host --user root -p123qwe

Here is my network structure.

| test      | RUNNING | (docker0)  | fd42:e8f7:40f5:2333:216:3eff:fe43:b9ad (eth0) | CONTAINER | 0         |
|           |         | (eth0) |                                               |           |           |


Thanks a lot for the answer @cemzafer .

I figure out what’s the problem. I had forgotten to set the -e parameter MARIADB_DATABASE when i was starting the docker container :slight_smile: . The fact that I was starting the mariadb container with -d ( detach mode) was preventing me from seeing the logs of the docker container and figure out the solution.

1 Like