Open nillander opened 4 weeks ago
That's odd -- REDMINE_DB_PORT
should be working. :thinking:
Anything interesting in your logs? Does the entrypoint-generated config/database.yml
file successfully include the specified port?
That's odd --
REDMINE_DB_PORT
should be working. 🤔Anything interesting in your logs? Does the entrypoint-generated
config/database.yml
file successfully include the specified port?
Nothing interesting in my logs, just that the specified database (redmine_db) was not found.
I even tried connecting to the container and telnetting to the database, but it only works if it is on port 3306. Even if I start separate containers for redmine and the database, I can only access the database container if it is on port 3306.
At another time I tried with the config/database.yml
file but I was not successful in specifying the port.
I believe that there must be some configuration in the image that does not allow the main Redmine container to see the database except on port 3306.
I found https://www.redmine.org/projects/redmine/wiki/RedmineInstall#Step-3-Database-connection-configuration which verifies that the way we're setting port:
should be correct -- I also verified that when I set it, we do generate port:
correctly in the config/database.yml
.
The only thing I can think of is that we're setting port: "1234"
vs the port: 1234
from the examples, but it would be really weird for it to silently ignore that, especially in an otherwise dynamically typed language accepting input from a dynamically typed file format. :thinking:
I've been trying exactly this way, and it only works with port 3306
Oh, when you use ports:
in that way, that's publishing the port externally, not internally, and your redmine
container is connecting to the internal hostname, so MySQL is always running on port 3306, but if you connected to that host from a machine outside the host you're running this on, you'd be able to hist 3307 instead.
Unless you actually need external access to that database, I'd definitely recommend keeping that tight and only allowing access to it inside the Docker network (ie, removing ports:
from your YAML block for MySQL entirely).
Yes, we keep the doors open to use phpmyadmin and also so that we can use some integrations with other systems. Still, I couldn't figure out how the Redmine container can't access the MySQL container if it's not on port 3306.
If you change MYSQL_HOST_NAME
to the external IP/hostname of the system, the remapped port should work. If you want MySQL itself to listen on a different port, you have to reconfigure it to do so.
I believe you could accomplish that with something like command: --port=${MYSQL_HOST_PORT}
on your MySQL container (and then also changing ports:
to map the same port on both sides), but that's probably overkill IMO.
I've already tried using the hostname itself, which is redmine_db
, instead of MYSQL_HOST_NAME
, but it still didn't work.
The problem isn't with MySQL, because we're using it normally with phpMyAdmin. During a test, we used it on port 3307 and pointed it to phpMyAdmin, which worked normally. We also validated the connection through MySQL Workbench on port 3307. The problem is in the Redmine container.
I made the changes today to use the config/database.yml
file as you said, and it still only works if the port indicated in the file is port 3306.
redmine_db
is the hostname of your container, so it will resolve from within the container to the container IP, not the external host IP (even if your external hostname is also redmine_db
).
Your MySQL instance is running (inside the container) on port 3306 in all these configurations. The ports:
field in the YAML does not change what port the service listens on. All that changes, is exposing that port externally from the host for other external services/hosts to connect to it, with the specified mapping. So when that is 3307:3306
, your host will have port 3307 open, and any traffic to 3307 on the host will be routed to 3306 inside your redmine_db
container.
So when you specify that you want Redmine itself to connect to redmine_db
, it resolves that to the container IP, which again is not listening on port 3307 in any of your configurations, and that's why Redmine fails to connect to it. The only IP address which has port 3307 in this setup is the host IP.
To make it less confusing, you could use:
redmine_db:
ports:
- '${MYSQL_HOST_PORT}'
environment:
MYSQL_TCP_PORT: ${MYSQL_HOST_PORT}
This would keep the port consistent inside and outside of the container space.
To make it less confusing, you could use:
redmine_db: ports: - '${MYSQL_HOST_PORT}' environment: MYSQL_TCP_PORT: ${MYSQL_HOST_PORT}
This would keep the port consistent inside and outside of the container space.
Thank you for your attempts to help, I have tried the alternatives of both @LaurentGoderre and @tianon but without success yet. I would appreciate if you could look directly at my repository, it is well organized, I welcome suggestions.
I just want to use MySQL on a port other than the default 3306
Your problem is because you are trying to use both env var and a config file and they are conflicting.
This block here doesn't have the port
https://github.com/nillander/Redmine/blob/main/Docker/pma/config.inc.php#L37
Adding this makes it work
$cfg['Servers'][$i]['port'] = 3307;
I also made a mistake for the port section, it should be
redmine_db:
ports:
- '${MYSQL_HOST_PORT}:${MYSQL_HOST_PORT}'
Your problem is because you are trying to use both env var and a config file and they are conflicting.
This block here doesn't have the port
https://github.com/nillander/Redmine/blob/main/Docker/pma/config.inc.php#L37
Adding this makes it work
$cfg['Servers'][$i]['port'] = 3307;
I also made a mistake for the port section, it should be
redmine_db: ports: - '${MYSQL_HOST_PORT}:${MYSQL_HOST_PORT}'
I'm sorry for the question, but have you tested your suggestion? I tested it here and it didn't work, I did exactly as you said, and I need to say that:
the change > $cfg['Servers'][$i]['port'] = 3307; doesn't make sense because this is just about telling phpMyAdmin which port the MySQL server is running on, remember, I have no problems with PMA, which works correctly even with MySQL on another port
redmine_db: ports:
If you can help, I'd appreciate it. This issue of Redmine not recognizing another non-standard MySQL port seems far from over.
Try cloning the repository and making the changes
I have tried all of the different combination and they all work. If all you want is to expose the db externally with a different port, you don't need to set the REDMINE_DB_PORT
at all because within the scope of the containers they all use the default port.
If you want the Redmine container to access MySQL at a specific port, then MySQL must be instructed to listen at that port. The port
mapping of docker
and docker-compose
does not affect the ports that containers access each other, it only affects host ports (i.e. usually external access).
services:
redmine:
image: redmine:5
environment:
REDMINE_DB_MYSQL: ${MYSQL_HOST_NAME}
REDMINE_DB_PORT: ${MYSQL_CONTAINER_PORT}
# etc ...
redmine_db:
image: mysql:8.0
ports:
- '${MYSQL_HOST_PORT}:${MYSQL_CONTAINER_PORT}'
command:
- -P
- '${MYSQL_CONTAINER_PORT}'
#...
MYSQL_HOST_NAME=redmine_db
MYSQL_HOST_PORT=3307
MYSQL_CONTAINER_PORT=9999
In this partial example, MySQL would be listening on port 9999 and Redmine would access at 9999. To an external party or accessing it via one of the hosts IP addresses, MySQL would be at 3307 (e.g., localhost:3307
from the Docker host).
When defining a database connection port in the environment variables of the redmine container, using the redmine:5.1.3 image (latest), it is possible to define in the environment variables the values REDMINE_DB_MYSQL, REDMINE_DB_DATABASE, REDMINE_DB_USERNAME, REDMINE_DB_PASSWORD but it is not possible to successfully define the REDMINE_DB_PORT variable, where I want to specify a port other than the default (3306) when using the MySQL database