Richten Sie einen Docker-Container ein, um mit einer lokalen Datenbank zu arbeiten

4409
Sekhemty

Ich versuche, einen Docker-Container so einzurichten, dass er mit einer lokalen Datenbank arbeitet.

Das Bild ist dieses https://hub.docker.com/r/tuxgasy/dolibarr/ und es wird empfohlen, auch einen mariadbContainer zu erstellen und diesen zu verknüpfen.

Ich möchte den Dolibarr-Container so konfigurieren, dass er stattdessen die mariadbDatenbank verwendet, die ich bereits auf meinem Hauptsystem habe, die vom Haupt-Repo meiner Distribution installiert wurde.

Es ist das erste Mal, dass ich versuche, eine funktionierende Docker-Anwendung einzurichten, und ich bin kein Experte für die Datenbankwartung. Ich bin also etwas verloren.

Wie kann ich das machen? Bitte halten Sie die Anweisungen so klar und detailliert wie möglich.

Mein System ist ein vollständig aktualisiertes openSUSE Tumbleweed.

3

1 Antwort auf die Frage

4
Clive Makamara

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