1

I am facing a strange problem with my docker. I had to reinstall it as in the following link: Docker Installation on Ubuntu 18.04

I did this installation before, so everything worked out fine. Then I created the network like this:

docker network create --subnet=172.18.0.0/16 mynet123

And finally built my container. But it can't connect to a database remote server. It gives the following error:

enter image description here

So I checked my internet connection from inside docker container and it turned out that I don't have it. So I guess that's the root of the problem. I tried reinstalling docker, changing docker network by specifying other subnet, followed this instruction Stackoverflow solution

But still no result. Does anybody have an idea how I can sort this out?

By the way, this is how I connect to MySQL using python:

dbconn = mysql.connector.connect(host=config["mysql"]["host"], database=config["mysql"]["database"], user=config["mysql"]["user"], password=config["mysql"]["password"])
cursor = dbconn.cursor()

And here is my config:

[mysql]
host = X.X.X.X.
database = database_name
user = root
password = password

*X.X.X.X here is an IP address of the remote host

P.S. I can connect to the remote database from my local machine, containers can connect to the database server via default network. All user permissions in my database are given.

arti_lina
  • 95
  • 2
  • 8
  • First, please consider [pasting actual code instead of uploading screenshots](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Second, what does `ifconfig` show you in terms of the `docker0` interface? Also, what does a simple `docker run --rm busybox ping -c1 stackoverflow.com` show you? – bellackn Jun 04 '19 at 09:50
  • @bellackn I've edited the question as you suggested. docker run --rm busybox ping -c1 stackoverflow.com shows me the following output: PING stackoverflow.com (151.101.1.69): 56 data bytes 64 bytes from 151.101.1.69: seq=0 ttl=57 time=142.462 ms – arti_lina Jun 04 '19 at 10:14
  • @bellackn what exactly is imporntant in `ifconfig docker0` output? – arti_lina Jun 04 '19 at 10:16
  • Hm, apparently nothing, because your connection works when you're not in the `mynet123` network. Does the ping work if you're in this network? I.e. `docker run --rm --net mynet123 busybox ping -c1 stackoverflow.com` – bellackn Jun 04 '19 at 10:21
  • @bellackn here is the output for `docker run --rm --net mynet123 busybox ping -c1 stackoverflow.com`: ping: bad address 'stackoverflow.com' – arti_lina Jun 04 '19 at 10:26
  • Ok, then there is something wrong with `mynet123`. To rule out a firewall problem, could you please create a network like `docker network create foo` (i.e. without subnet) and try to run busybox from there again? Also, what you could try is to specify the gateway to `mynet123` by deleting it and then recreating it like `docker network create mynet123 --subnet 172.18.0.0/16 --gateway 172.18.0.1`. – bellackn Jun 04 '19 at 10:34
  • @bellackn it works without subnet, but when I add gateway and subnet it crushes. But I do need to assign static ip to my containers:( – arti_lina Jun 04 '19 at 11:41
  • @bellackn I've changed net-work subnet to 172.19.0.0/16 and it worked out! Do you know the reason for this? – arti_lina Jun 04 '19 at 11:54
  • 1
    Glad it works! I cannot answer that because I don't know your network infrastructure. – bellackn Jun 04 '19 at 12:10

0 Answers0