compose: `Host name lookup failure` or missing networks when using multiple networks

_Originally posted by @ToshY in https://github.com/docker/compose/issues/10668#issuecomment-1615217336_:

@milas While this seems to fix the not connected to network issue, it gave me a forward host lookup failed: Host name lookup failure in return when running waisbrot/wait with docker compose run.

Example

version: '3.9'
  
services:
  mysql:
    image: ${MYSQL_IMAGE_VERSION}
    ports:
      - "3308:3306"
    environment:
      MYSQL_USER: ${DATABASE_USER}
      MYSQL_DATABASE: ${DATABASE_NAME}
      MYSQL_ROOT_PASSWORD: ${DATABASE_ROOT_PASSWORD}
      MYSQL_PASSWORD: ${DATABASE_PASSWORD}
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - webapp

  wait:
    image: waisbrot/wait
    environment:
      TARGETS: mysql:3306
      TIMEOUT: 300
    networks:
      - webapp

volumes:
  mysql_data:
    driver: local

networks:
  webapp:
    driver: bridge
$ docker compose up -d
[+] Running 4/4
 ✔ Container webapp-wait-1    Started                                                                                                                                                         3.0s
 ✔ Container webapp-mysql-1   Started                                                                                                                                                         2.9s

$ docker compose run --rm wait
Waiting for mysql:3306  .mysql: forward host lookup failed: Host name lookup failure
.mysql: forward host lookup failed: Host name lookup failure
.mysql: forward host lookup failed: Host name lookup failure

$ docker compose ps
NAME                            IMAGE                         COMMAND                  SERVICE             CREATED             STATUS              PORTS
webapp-mysql-1                  mysql:8.0                     "docker-entrypoint.s…"   mysql               8 minutes ago       Up 5 minutes        33060/tcp, 0.0.0.0:3308->3306/tcp, :::3308->3306/tcp

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 13
  • Comments: 18 (7 by maintainers)

Commits related to this issue

Most upvoted comments

A fix has been released for this: https://github.com/docker/compose/releases/tag/v2.20.0

@johnthagen It’s possible to temporarily override the version of Compose in Docker Desktop. (It will be overwritten on the next Docker Desktop upgrade.)

curl -L -o /tmp/docker-compose 'https://github.com/docker/compose/releases/latest/download/docker-compose-darwin-aarch64' && \
  mv /tmp/docker-compose "${HOME}/.docker/cli-plugins/docker-compose" && \
  chmod +x "${HOME}/.docker/cli-plugins/docker-compose" && \
  docker compose version

Heyo. We just ran into this. The container is only added to one network, so dns doesn’t resolve. Appears to be a regression

I’m on

Docker Compose version v2.20.2-desktop.1

I’m facing this bug. I’m on Windows.

IIRC it was introduced in 2.18.1 or 2.19.0. Nicely fixed in 2.20.0.

Got same problem. Postgres service on docker network fails to be recognized randomly.