dockerdocker-composegithub-actionsdocker-networkgithub-actions-runners

Accessing internet from container, running in GitHub Actions


I would like to ping some external IP from inside of a container, running in GitHub Actions.

I have a simple GitHub action (consider this workflow):

name: PING

on:
  push:

jobs:
  ping:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Ping Internet
        run: docker-compose -f test/docker-compose.yml up --force-recreate --build --abort-on-container-exit

and a simple docker-compose file:

version: '3.1'

services:
  pinger:
    privileged: true
    image: alpine:3.17
    command: ping -c 16 -s 64 8.8.8.8
    networks:
      default:
        ipv4_address: 10.0.0.5

networks:
  default:
    driver: bridge
    ipam:
     config:
       - subnet: 10.0.0.0/24
         gateway: 10.0.0.1

Now, the docker-compose -f test/docker-compose.yml up --force-recreate --build --abort-on-container-exit command runs perfectly fine locally, but fails in GitHub Actions environment - apparently, no ping responses can be received, so I assume Internet to be unreachable.

Do anyone has any ideas, why can this be happening?
Maybe because of GitHub Actions environment nature I should connect to some exieting network or specify it somehow?
How can I access Internet from my Docker container, running inside of a GitHub Action?


Solution

  • Recently, I found out that ping doesn't work in GitHub actions at all because the hosted runner uses a specific type of Azure machine that doesn't allow it by design :(