Connecting to Docker host MySQL from Docker Container: Linux Ubuntu
Let’s face it. Connecting to the host machine from Docker containers in Linux is frustrating. After hours of googling + trial and errors + crying, I came up with this solution which I’m happy to share it with you.
Why bother?
Both windows and mac version of Docker offers a convenient method of resolving the Dockerhost IP by calling host.docker.internal. Unfortunately at the time of writing this article, host.docker.internal does not work for Linux users.
Prerequisite
- Familiarity with Docker network and basic docker commands.
- Basic knowledge on TCP/UDP ports
1. Add Dockerhost to your docker-compose file:
Add and install this awesome docker container to your project. This container will forward any traffic to your host machine.
# docker-compose.ymldockerhost:
image: qoomon/docker-host
cap_add:
- NET_ADMIN
- NET_RAW
restart: on-failure
networks:
- backend
- frontend