Is it possible to connect wit the docker setup to a database on the same workstation ?
Added by Christian Eichert about 1 year ago
I have a docker setup on my workstation, and I was up to connect it to the localhost MySQL database. (like this :)
services:
redmine:
image: redmine:alpine
restart: always
ports:
- 80:3000
environment:
REDMINE_DB_MYSQL: 127.0.0.1
REDMINE_DB_PORT: 3306
REDMINE_DB_USERNAME: redmine
REDMINE_DB_PASSWORD: redmine
REDMINE_DB_DATABASE: redmine
REDMINE_SECRET_KEY_BASE: supersecretkey
I was not successful because the container was trying to connect inside to the 127.0.0.1, respectively to the socket.
what is the right setup for this?
Replies (2)
RE: Is it possible to connect wit the docker setup to a database on the same workstation ?
-
Added by Pav ata 10 months ago
If by "same workstation" you mean the host system to your containers, then..
To container 127.0.0.1 is its own loopback device.
On Linux host I'd use a docker/podman network (default, I think, is of bridge type) which gives access to the host, then I'd connect Redmine to a newly created - for containers purposes - 'dummy' iface on the host(making sure relevant services, on the host, listen on it and also firewalls are taken into account)
RE: Is it possible to connect wit the docker setup to a database on the same workstation ?
-
Added by Lionel BAKALA 9 months ago
Hi Christian,
In bridge network mode, each container has a "Gateway" address that represents the host.
For a network named redmine_default, we have the following configuration:
docker network inspect redmine_default | grep -Ew "Gateway|Name|IPv4Address" | sed 's/^[[:space:]]*//' "Name": "redmine_default", "Gateway": "172.25.0.1" "Name": "redmine-mariadb-1", "IPv4Address": "172.25.0.2/16", "Name": "redmine-redmine-1", "IPv4Address": "172.25.0.3/16",
172.25.0.1 is the host machine's address as seen from the containers within the redmine_default network.
And the question is: Which Docker network is my container using ?
Kind regards.