0

What I want to do

  • Set up a backend server inside a Docker for Mac container.
  • Access MySQL from that server, which is running on a host.

Things you can't do

  • Connect to MySQL from Docker for Mac.

Things I've tried

  • Started a container using host.docker.internal as follows.
docker run --rm -it --add-host=host.docker.internal:host-gateway ubuntu:22.04 sh start.sh

The url for sending a request to MySQL is as follows

app@tcp(127.0.0.1:3306)/app_name?parseTime=true&charset=utf8mb4
```

musako
  • 897
  • 2
  • 10
  • 26
  • the way it is written is kind of hard for me to follow. but i will do something like use docker compose to stand up 2 containers, 1 for the Backend and 1 for MySql. Then i would expose the Mysql 3306 port so I can access it on my host to verify with apps like DBeaver etc. It sounds though that youre trying to set up the Docker Container (backend) to talk to the Host Mysql DB? Why not abstract from Host and put it on your own container? – Fallenreaper May 29 '23 at 19:25
  • In Docker, 127.0.0.1 almost always refers to the current container, not the host system or another container. You need to change that; if `host.docker.internal` works then that will be the correct host name. – David Maze May 30 '23 at 09:38

1 Answers1

0
app@tcp(127.0.0.1:3306)/app_name?parseTime=true&charset=utf8mb4

to

app@tcp(host.docker.internal:3306)/app_name?parseTime=true&charset=utf8mb4

then

docker run --rm -it --add-host=host.docker.internal:host-gateway ubuntu:22.04 sh start.sh
Hernan Garcia
  • 1,416
  • 1
  • 13
  • 24
musako
  • 897
  • 2
  • 10
  • 26