Skip to content

Stable port number for accessing mysql and http on localhost #941

Closed

Description

@tmotyl

Is your feature request related to a problem? Please describe.
I'm using mysqlworkbench to connect to ddev database using external port (found using ddev describe). The problem is that every time ddev is restarted the port changes, which means I need to reconfigure mysqlworkbench. This is very annoying.

Describe the solution you'd like
The mysql port should not change after restarting ddev.

Activity

  1. changed the title [-]Stable external ports for accessing mysql[/-] [+]Stable port number for accessing mysql[/+] on Jun 26, 2018
  2. rfay commented on Jun 26, 2018

    @rfay
    Member

    I don't know of a way to accomplish this, since the localhost port binding is managed on ephemeral ports by docker. Of course http-based services (like phpmyadmin) use ddev-router for access, so they stay in a defined http-space.

  3. tmotyl commented on Jun 26, 2018

    @tmotyl
    ContributorAuthor

    can the port binding be generated once on ddev config and then saved in config.yaml?

  4. rfay commented on Jun 26, 2018

    @rfay
    Member

    Maybe. Seems like this wouldn't work at all for teams that check in their config.yaml. Every machine would have various kinds of conflicts based on what projects they were running.

  5. tmotyl commented on Jun 26, 2018

    @tmotyl
    ContributorAuthor

    In case of conflict I'm ok if the port is adapted.

  6. rickmanelius commented on Jun 26, 2018

    @rickmanelius
    Contributor

    FWIW, there was a related request by @mglaman but solving this in a different way. See #691. Basically, rather than pinning the port numbers (and this will become problematic if users are working across multiple teams and they start to conflict), surface a way to expose the port number by exporting a file OR exposing it via ddev describe -j. Of course this might not help the use case of this issue because I don't think mysqlworkbench could pull this information.

  7. rfay commented on Jul 16, 2018

    @rfay
    Member

    in #691 I asked if this current output (published_port) from ddev describe -j is adequate to solve this problem:

        "raw": {
            "approot": "/Users/rfay/workspace/d7git",
            "dbinfo": {
                "dbname": "db",
                "host": "db",
                "password": "db",
                "port": "3306",
                "published_port": "32848",
                "username": "db"
            },
    
  8. tmotyl commented on Jul 16, 2018

    @tmotyl
    ContributorAuthor

    an alternative solution which would work for mysql workbench, would be to allow ddev to expose ssh serwer, then mysql workbench could connect through ssh tunnel.
    But then again we have an issue with ports.

    Or maybe we could have a similar proxy/router we have for http traffic, so stuff like:
    mysql -h myprojectname.ddev.local -p
    would work from the host machine?
    I mean, the mysql proxy would be exposed always on some port like 3366 and then route the traffic to the correct container based on the domain?

  9. rfay commented on Jul 16, 2018

    @rfay
    Member

    Yeah, there's no ssh tunneling with ddev ssh, because it's actually docker exec which isn't actually related to ssh.

    There's no way to redirect mysql traffic like we do with ddev-router, because there's no Host header or equivalent.

    That doesn't mean we can't find some way that this will work out for you!

  10. indytechcook commented on Aug 2, 2018

    @indytechcook

    FWIW, lando allows this sort of configuration in the .lando.yml. I'm not sure it helps but perhaps we can see how they handle this flexibility. Sorry if it doesn't help.

    services:
      database:
        portforward: 32780
    
  11. rickmanelius commented on Aug 2, 2018

    @rickmanelius
    Contributor

    So allowing the ability to specify the port in a yaml file is certainly a consideration... but in thinking through the use case of many projects shared over many people, it could become more management to lock in all the ports.

  12. mfrieling commented on Aug 8, 2018

    @mfrieling

    rather than pinning the port numbers (and this will become problematic if users are working across multiple teams and they start to conflict)

    Maybe you can add a syntax element to keep it dynamic, e. g.
    published_port: auto
    This way users or teams who need a fixed port for external tools can pin the port and those for whom it will be problematic can still use dynamic port assignment like now. Dynamic port assignment should be the default config then.

  13. outdoorsman commented on Sep 25, 2018

    @outdoorsman
    Contributor

    Not sure I have any more answers but am seconding the desire to be able to set up a mysql workbench connection and not have to keep revisiting it with new port numbers.

  14. rfay commented on Sep 25, 2018

    @rfay
    Member

    Just an FYI that for macOS users ddev sequelpro is a beloved command.

  15. rfay commented on Sep 25, 2018

    @rfay
    Member

    I guess it would be super easy to add support for other database browsers in the exact same way as ddev sequelpro. That's a different way forward on this.

  16. 5 remaining items

  17. indytechcook commented on Jan 30, 2019

    @indytechcook

    @rfay that's my use case, I'm using datagrip and keep having to change the port in the config.

  18. kaystrobach commented on Feb 7, 2019

    @kaystrobach

    the biggest problem is, that most tools have their own import / export format for that data ...

  19. unherz commented on Feb 11, 2019

    @unherz

    As a workaround you can write a bash script which executes the command ddev describe -j | jq -r .raw.dbinfo.published_port (thats what @rfay mentioned and it works great thx) and save the output as variable. So you can call it on your console without caring about the specific published port.

    Also per docker ps you can view all the published and formarded ports.

    But in the future it would be great to manually configure it

  20. tmotyl commented on Feb 11, 2019

    @tmotyl
    ContributorAuthor

    What about approach like:

    1. allow to configure port in yaml file (by default you dont have to do it, but you can)
    2. when running ddev start, ddev checks if the port is already taken and:
    • if its free, then it binds to the configured port
    • if it's taken, then it warns the user and bind to the random port number
    1. ddev remembers the last port number which was used (inportant in case it was a random number) and on the next start tries to use the same port as before. So it changes the port only when there is a conflict.
  21. unherz commented on Feb 11, 2019

    @unherz

    Recently a co-worker mentioned that you actually CAN set a stable port number:
    Just create a config file: docker-compose.environment.yaml (obviously you can change the name) and add your config under services - db - ports.
    As example:

    services:
      db:
        ports:
          - 32780:3306
    

    In this example 32780 will be the forced stable port.
    Actually I dont know in which version this feature came up.

    Please correct me if im wrong!

    So this issue can be closed

  22. rfay commented on Feb 11, 2019

    @rfay
    Member

    Thanks for the workaround @unherz ! So amazing what can be done with a little docker-compose magic. I'd like to keep this open because for both localhost webserver binding and db binding it would be so useful for it to be static.

  23. added a commit that references this issue on Mar 20, 2019
    22419d4
  24. added this to the v1.6.1 milestone on Mar 20, 2019
  25. rfay commented on Mar 20, 2019

    @rfay
    Member

    There's a PR with artifacts to test on #1502 (comment) and I'd love to have some feedback on it.

  26. added a commit that references this issue on Mar 28, 2019
    9fb54a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Prioritized

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions