Docker compose container cannot access internet

Docker version 26.1.4, build 5650f9b
Docker Compose version v2.34.0

Running wget http://google.com from my host succeeds.

Running the same command from a container started using docker run -it --rm alpine succeeds.

Running the same command from a container started using docker compose run --rm --remove-orphans test fails (it resolves DNS but the download times out).

The docker-compose.yml is simply:

services:
  test:
    image: alpine
    networks:
      - my-test
networks:
    my-test:

I’ve tried explicitly adding driver: bridge to the network. This does not work.

I’ve tried changing the service from networks: my-test to network_mode: bridge. This does work, but isn’t desirable since I want it to have a custom network for isolation and service aliases.

How do I diagnose this further, or ideally fix it?

I would start by updating Docker to the current version, which is 28.0.4.

I was testing with Docker 26 because that’s the version currently available to GitHub runners.

But the same issue occurs with Docker version 28.0.4, build b8034c0 – docker containers work, docker compose services do not.

Oddly, this started working after rebooting the host.

Restarting the docker service was not sufficient.