Score:1

How to fix networks conflict between WSL and Docker compose?

gd flag

Few days ago, on WSL2 (Ubuntu 20.04), I installed docker compose and created a docker-compose.yml that builds a database based on postgres:12 image. The first time I ran it, everything worked fine.

A few days later, when I ran my docker compose again, the build didn't work. Docker cannot access to internet to pull the postgres image, the connection is refused. Here is what it said :

$ docker compose up -d

[+] Running 1/0
 ! database Warning                                                                                                                              
[+] Building 0.0s (3/3) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                
 => => transferring dockerfile: 290B                                                                                                                
 => [internal] load .dockerignore                                                                                                                   
 => => transferring context: 2B                                                                                                                     
 => ERROR [internal] load metadata for docker.io/library/postgres:12-alpine                                                                         
------
 > [internal] load metadata for docker.io/library/postgres:12-alpine:
------
failed to solve: postgres:12-alpine: failed to do request: Head "https://registry-1.docker.io/v2/library/postgres/manifests/12-alpine": dial tcp: lookup registry-1.docker.io on 172.18.0.1:53: read udp 172.18.0.1:51217->172.18.0.1:53: read: connection refused

So I checked if I still had an Internet access in WSL by trying sudo apt-get update or ping google.com and I didn't...The fact is I just don't have any internet access anymore in WSL since that day.

$ ping www.google.com
ping: www.google.com: Temporary failure in name resolution

What I have tried :

  • I tried to go into /etc/resolve.conf and modify nameserver address by enter google DNS, 8.8.8.8, instead of the default address. resolve.conf content :
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateR.esolvConf = false
nameserver 8.8.8.8

I have even created a wsl.conf to keep the nameserver 8.8.8.8. After that, my problem was fixed for a few minutes but it all crashes again.

  • The docker error is not the same if I change nameserver in resolve.conf. With default nameserver, if I want to pull postgres image in docker, I have a connection refused (like with docker compose) :
$ docker pull postgres
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": dial tcp: lookup registry-1.docker.io on 172.18.0.1:53: read udp 172.18.0.1:57439->172.18.0.1:53: read: connection refused

And with nameserver 8.8.8.8, I have a timeout error from docker :

$ docker pull postgres
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": dial tcp: lookup registry-1.docker.io on 8.8.8.8:53: read udp 172.18.7.177:46999->8.8.8.8:53: i/o timeout
  • Strange thing though, if I reboot my PC and then run WSL, I have an ephemere internet connection, around 2mins, (if i do a sudo apt-get update, it works), and it finally loses any connection then.

I think docker or docker compose must have created conflict in my WSL networks, maybe an IP address already used by something else, but I can't explain how. Here is my Docker and Docker compose version.

Docker version 23.0.3, build 3e7cbfd
Docker Compose version v2.17.2

Thanks for your help, I honestly don't know what to do.

Sean Cavanagh avatar
am flag
What do you get from `ip route`?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.