0

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?

pseusys
  • 407
  • 2
  • 5
  • 17
  • 1
    "**I assume Internet to be unreachable**", you can verify this by running that `ping` command in a step directly under `run` i.e. `run: ping -c 16 -s 64 8.8.8.8`. – Azeem May 16 '23 at 07:52
  • BTW, how did you configure the network i.e. `ipv4_address`, `subnet`, and `gateway`? – Azeem May 16 '23 at 07:59
  • 1
    @Azeem, yes, I configured the network, but it [turns out](https://github.com/actions/runner-images/issues/1519#issuecomment-683790054) thet ping doesn't work in GitHub actions at all :( – pseusys May 16 '23 at 11:55
  • Right. Thanks for sharing that link! BTW, what is your use case? What were trying to solve with `ping`? – Azeem May 16 '23 at 12:51
  • @Azeem, I was trying to test some network confifurations (`ip route`s and `iptables`) using `ping`, but eventially found the `nc` (netcat) commang that allows connecting to `tcp` and `upd` servers that can be used for network connecting checking just the same. – pseusys May 16 '23 at 13:40
  • Right. Yes, netcat should work fine for this. But, `ping` works with ICMP which is a Layer 3 protocol whereas TCP/UDP are Layer 4 protocols so it's not the same thing. – Azeem May 16 '23 at 15:46

0 Answers0