1

I was reading a, here, here, here, here, here

none of which answers my question.

What I want to do?

I have a mysql docker-compose image and want to connect to it from my ubuntu host using

localhost:3306

this does not work

it does work if I use

0.0.0.0:3306

which is not what I want to do. Why do I want to do all of that? because I have to start to work on an oooold legacy app, that has an old mysql version. Now I have mysql 8.0 on my computer and dont want to downgrade just for that one project. The legacy code has about 1000 references to localhost:3306 in it. Now I could refactor all that, create a config file etc... but better would be, if I could make it work so that localhost:3306 actually accesses my mysql docker-compose container. Is that possible? What do i have to add to my docker-compose yaml file?

my mysql docker-compose yaml file is this:

version: '3.3'
services:
  sciodb:
    container_name: sciodb
    image: mysql:5.6
    restart: always
    environment:
      MYSQL_DATABASE: 'db'
      # So you don't have to use root, but you can if you like
      MYSQL_USER: 'myuser'
      # You can use whatever password you like
      MYSQL_PASSWORD: 'test1234'
      # Password for root access
      MYSQL_ROOT_PASSWORD: 'test1234'
    ports:
      # <Port exposed> : < MySQL Port running inside container>
      - '3306:3306'
    expose:
      # Opens port 3306 on the container
      - '3306'
      # Where our data will be persisted
    volumes:
      - /home/myuser/nmyapp_db:/var/lib/mysql
      - /media/sf_vmwareshare:/var/vmwareshare
15
  • Is this your whole yml file? Is there a network portion? By default the docker should run in bridge mode and since you've exposed the port to mysql (and assigned to a network?), you should be able to connect via localhost:3306. Is Everything else configured properly within the mysql config files to allow remote connections in /home/myuser/nmyapp_db? for reference, I have a webapp running in a container on a centOS server on port 7878 and curl localhost:7878 returns the webpage. Can you connect via telnet to localhost:3306? What does docker ps show for the container? Commented May 19, 2019 at 4:18
  • Did you try to connect your DB from your system or a other container? For the last case: Did you tried network_mode: host in your docker-compose? Commented May 19, 2019 at 7:18
  • @user1628449 this is my whole yml file, no network portion. If I run telnet localhost 3306 I get asked "mysql_native_password" so it seems to work. It can be that the old php 5.6 mysql_connect somehow cannot do it for some weird reason. Curl works the same from command line.... @Wie I tried to connect from my own system to the docker container. network_mode: host would need to be on what level? I put it directly into the service e.g. sciodb. But still get No such file or directory when trying to connect via php to mysql Commented May 19, 2019 at 19:08
  • @user1628449 how is that a remote connection? btw I noticed I can connect with phpmyadmin, just not mysql_connect Commented May 19, 2019 at 19:14
  • where does the app that is running php live? In another container or on the host machine? localhost within the container is not loaclhost on the host machine as the docker network has it's own subnet. Also, what error is php throwing? Commented May 20, 2019 at 1:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.