joeyates / imap-backup

Backup and Migrate IMAP Email Accounts
MIT License
1.33k stars 74 forks source link

Docker DNS access #187

Closed airdogvan closed 7 months ago

airdogvan commented 7 months ago

Because the docker container does not have access to the host DNS I think you have to add the --dns=8.88.8.8 option, otherwise your email server address won't resolve.

So, instead of

docker run -ti -v ./my-config:/config -v ./my-data:/data -ti ghcr.io/joeyates/imap-backup:latest \ imap-backup setup -c /config/imap-backup.json

You need to run

docker run --dns=8.8.8.8 -ti -v ./my-config:/config -v ./my-data:/data -ti ghcr.io/joeyates/imap-backup:latest \ imap-backup setup -c /config/imap-backup.json

Of course you can replace 8.8.8.8 with any DNS server that can resolve domain names.

joeyates commented 7 months ago

Hello @airdogvan

Thanks for opening this issue.

I've just tried to run the backup of a GMail account without the additional DNS setting, and it worked.

I then ran the following:

$ docker run --pull always --rm -it ghcr.io/joeyates/imap-backup:latest ping imap.gmail.com

This is the output:

latest: Pulling from joeyates/imap-backup
Digest: sha256:ac02c158182fceb22d03437e8d013d6201b024a2c66c1dc842f9ecf6616f6a02
Status: Image is up to date for ghcr.io/joeyates/imap-backup:latest
PING imap.gmail.com (108.177.96.109): 56 data bytes
64 bytes from 108.177.96.109: seq=0 ttl=50 time=75.996 ms
64 bytes from 108.177.96.109: seq=1 ttl=50 time=74.505 ms

Could you do the same with your setup and your IMAP server(s)?

airdogvan commented 7 months ago

tried it with gmail and it works (is the IP hard coded in the image?) but doesn't if I try my server. If you want to see how it works try: docker run --pull always --rm -it ghcr.io/joeyates/imap-backup:latest ping imap.mail.yahoo.com

that should return: ping: bad address 'imap.mail.yahoo.com'

Your container needs some way to resolve addresses and without access to a DNS server that's always going to be a problem...

joeyates commented 7 months ago

I read a very informative post about Docker DNS, and learned that Docker containers' DNS resolution depends very much on the host configuration: nameservers are copied from the host into /etc/resolv.conf.

Mine:

$ docker run --pull always --rm -ti ghcr.io/joeyates/imap-backup:latest cat /etc/resolv.conf
...
nameserver 192.168.0.2
nameserver 8.8.8.8

If the host does not supply nameservers, Docker uses Google's 8.8.8.8 and 8.8.4.4.

So, DNS resolution for imap.mail.yahoo.com will fail if the host supplies 2 nameservers that are not reachable from the container.

I've added Google's main nameserver to the examples in the README, as suggested. Thanks!