3

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.

4

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

0

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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