18

I'm trying to setup a Docker container to work with a local database.

The image is this one https://hub.docker.com/r/tuxgasy/dolibarr/ and it suggests to also create a mariadb container, and link it to that.

I would like to configure the Dolibarr container to instead use the mariadb database that I already have on my main system, that was installed from my distro's main repo.

It's the first time that I try to setup a working Docker application, and I'm not that expert about database maintenance, so I'm a bit lost.

How can I do this? Please keep the instructions ad clear and detailed as possible.

My system is a fully updated openSUSE Tumbleweed.

1
  • Hey, I'm having the same issue on CentOS 7, can you share the command you use to create a container for tuxgasy/dolibarr using the host database ? – executable Jul 13 '20 at 8:20
24

There are three ways:

  1. Use the --net=host option. This network mode essentially means that the container has direct access to localhost and you can now access localhost:3306. Here's the command

    docker run --net=host ... tuxgasy/dolibarr

    Then connect to mariadb with localhost:3306

  2. Mount the mariadb socket to the docker container and connect to mariadb via socket. For example if you configure the socket's location to be /var/run/mysqld/mysqld.sock then you could mount and use that as your connection point.

    docker run -v /var/run/mysqld:/mariadb_socket ... tuxgasy/dolibarr

    Then connect to mariadb via the socket /mariadb_socket/mysqld.sock from your app

  3. Use the docker host's ip. First get the host ip address on the docker network (in linux type ip addr show and look for the docker0 ip). This is usually something like 172.17.0.1 (your mileage may vary). Then you should be able to use that ip address to connect to mariadb for example 172.17.0.1:3306

NOTE: ... means any other options that you may already be using

1
  • Note that net=host isn't available for macOS, so option 1 won't work. – Chris Vandevelde Jun 3 '20 at 19:02
2

I've created a docker container for doing exactly that https://github.com/qoomon/docker-host

You can then simply use container name dns to access host system from inside a container e.g. curl http://dockerhost:9200

2

As of Docker v18.03+ you can use the host.docker.internal hostname to connect to your Docker host.

This is for development purpose and will not work in a production environment outside of Docker Desktop.

link

-1

Keep in mind that qoomon/docker-host is no better than any other method. You must configure your application on docker host to bind and listen to docker bridge before it is accessible. In my opinion, qoomon/docker-host is just adding an extra layer to network packet, which provides no real advantage

This is the copy of README for qoomon/docker-host that people seems to miss. "On Linux systems you have to bind your host applications to bridge network gateway in addition to localhost(127.0.0.1), if you want to reach them through docker-host container. Use following docker command to get the bridge network gateway IP address"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.