0

I know this seems like a common situation but nothing which I've found helps.

I'm following the docker 'getting-started' guide verbatim, literally copy and pasting the commands. But when I get to this step:

docker run -dp 3000:3000 \
   -w /app -v "$(pwd):/app" \
   --network todo-app \
   -e MYSQL_HOST=mysql \
   -e MYSQL_USER=root \
   -e MYSQL_PASSWORD=secret \
   -e MYSQL_DB=todos \
   node:12-alpine \
   sh -c "yarn install && yarn run dev"

The log output is as follows:

{ Error: connect EHOSTUNREACH 172.18.0.2:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
  errno: 'EHOSTUNREACH',
  code: 'EHOSTUNREACH',
  syscall: 'connect',
  address: '172.18.0.2',
  port: 3306 }

Here is the catch, I can successfully connect to mysql running in the container from the host system:

$ mysql -h172.18.0.2 -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]>

Furthermore from the 'app' container, I can successfully ping the 'mysql' host. 'nc' is unable to connect though:

[mmorsi@localhost app]$ docker exec e8df2d36914 ping -c 3 mysql
PING mysql (172.18.0.2): 56 data bytes
64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.071 ms
64 bytes from 172.18.0.2: seq=1 ttl=64 time=0.173 ms
64 bytes from 172.18.0.2: seq=2 ttl=64 time=0.176 ms

--- mysql ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.071/0.140/0.176 ms
[mmorsi@localhost app]$ docker exec e8df2d36914 nc -z -v mysql 3306
nc: mysql (172.18.0.2:3306): Host is unreachable

Other things I've tried:

  • Running the latest mysql docker image
  • Running the 'app' on the centos:latest image (with the necessary steps to install deps)

My host system is Fedora 33. On the host, the docker0 interface is running in the 'trusted' zone (target: ACCEPT):

[mmorsi@localhost app]$ sudo firewall-cmd --get-active-zones
FedoraWorkstation
  interfaces: enp0s31f6
trusted
  interfaces: docker0
[mmorsi@localhost app]$ man firewall-cmd
[mmorsi@localhost app]$ sudo firewall-cmd --info-zone=trusted
trusted (active)
  target: ACCEPT
  icmp-block-inversion: no
  interfaces: docker0
  sources: 
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

I'm all out of ideas. Any help or insights would be highly appreciated.

2
  • Take a look at this, maybe you are having the same issue. For me, everything was configured correctly, but had to do a hard reset of everything for it to work. stackoverflow.com/questions/57980367/… Commented Dec 23, 2021 at 18:24
  • Try telnet inside the node docker (Whether the port is reachable) . And install mysql cilent inside the docker and try connecting. how you did from Host Commented Dec 24, 2021 at 0:06

1 Answer 1

1

Figured it out!

(Courtesy of https://fedoramagazine.org/docker-and-fedora-32/)

A simple:

sudo firewall-cmd --permanent --zone=FedoraWorkstation --add-masquerade

So as to allow docker to make local connections was all that was needed! (in addition to the other steps listed there which I had previously run).

[Proceeds to pat self on back]

Sign up to request clarification or add additional context in comments.

Comments

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.