Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment set REDMINE_DB_PORT doenst work #342

Open
nillander opened this issue Oct 4, 2024 · 15 comments
Open

Environment set REDMINE_DB_PORT doenst work #342

nillander opened this issue Oct 4, 2024 · 15 comments

Comments

@nillander
Copy link

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

image

@tianon
Copy link
Member

tianon commented Oct 7, 2024

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?

@nillander
Copy link
Author

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.

@tianon
Copy link
Member

tianon commented Oct 7, 2024

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. 🤔

@nillander
Copy link
Author

image
image

I've been trying exactly this way, and it only works with port 3306

@tianon
Copy link
Member

tianon commented Oct 8, 2024

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).

@nillander
Copy link
Author

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.

@tianon
Copy link
Member

tianon commented Oct 8, 2024

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.

@nillander
Copy link
Author

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.

@tianon
Copy link
Member

tianon commented Oct 9, 2024

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.

@LaurentGoderre
Copy link
Member

LaurentGoderre commented Oct 10, 2024

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.

@nillander
Copy link
Author

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

https://github.com/nillander/Redmine

@LaurentGoderre
Copy link
Member

LaurentGoderre commented Oct 11, 2024

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}'

@nillander
Copy link
Author

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:

  1. 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

  2. redmine_db:
    ports:

  • '${MYSQL_HOST_PORT}:${MYSQL_HOST_PORT}'
    This parameterization should refer to the exposure of external and internal ports of the container, where in the original file I'm saying that when accessing localhost:8080 I will be accessing the internal port 3000 of the container

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

@LaurentGoderre
Copy link
Member

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.

@yosifkit
Copy link
Member

yosifkit commented Oct 22, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants