Ping the network inside docker container from outside on the same host machine

30 Views Asked by At

I was following the setup for open5gs code here

Essentially I expose a sctp port 38412 from inside the container and fail to ping or connect to network from the same host machine the container is running on (single machine).

services:
  5gc:
    container_name: open5gs_5gc
    build:
      context: open5gs
      target: open5gs
      args:
        OS_VERSION: "22.04"
        OPEN5GS_VERSION: "v2.6.1"
    env_file:
      - ${OPEN_5GS_ENV_FILE:-open5gs/open5gs.env}
    privileged: true
    ports:
      - "3000:3000/tcp"
      # Uncomment port to use the 5gc from outside the docker network
      - "38412:38412/sctp"
    command: 5gc -c open5gs-5gc.yml
    healthcheck:
      test: ["CMD-SHELL", "nc -z 127.0.0.20 7777"]
      interval: 3s
      timeout: 1s
      retries: 60
    networks:
      ran:
        ipv4_address: ${OPEN5GS_IP:-10.53.1.2}

From inside the container, the ping works.

❯ docker exec -it open5gs_5gc bash
root@15e61fd8c4b3:/open5gs# ping 10.53.1.1
PING 10.53.1.1 (10.53.1.1) 56(84) bytes of data.
64 bytes from 10.53.1.1: icmp_seq=1 ttl=64 time=0.112 ms
64 bytes from 10.53.1.1: icmp_seq=2 ttl=64 time=0.040 ms
64 bytes from 10.53.1.1: icmp_seq=3 ttl=64 time=0.041 ms
^C
--- 10.53.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2051ms
rtt min/avg/max/mdev = 0.040/0.064/0.112/0.033 ms

From the host outside of the container, it doesn't:

❯ ping -c 4 10.53.1.2
PING 10.53.1.2 (10.53.1.2) 56(84) bytes of data.
From 10.53.1.1 icmp_seq=1 Destination Host Unreachable
From 10.53.1.1 icmp_seq=2 Destination Host Unreachable
From 10.53.1.1 icmp_seq=3 Destination Host Unreachable
From 10.53.1.1 icmp_seq=4 Destination Host Unreachable

--- 10.53.1.2 ping statistics ---
4 packets transmitted, 0 received, +4 errors, 100% packet loss, time 3049ms
pipe 4

The same error occurs after docker network prune and rebuilding docker compose.

This is an issue I raised for srsRAN_Project here. More details can be found in there.

UPDATE:
The high-level idea is to connect the open5gs part above to a gnb that was compiled on host-machine via sudo ./gnb -c gnb_zmq.yaml

The config gnb_zmq.yaml is as follows:

# This configuration file example shows how to configure the srsRAN Project gNB to allow srsUE to connect to it. 
# This specific example uses ZMQ in place of a USRP for the RF-frontend, and creates an FDD cell with 10 MHz bandwidth. 
# To run the srsRAN Project gNB with this config, use the following command: 
#   sudo ./gnb -c gnb_zmq.yaml

amf:
  addr: 10.53.1.2                  # The address or hostname of the AMF.
  bind_addr: 10.53.1.1             # A local IP that the gNB binds to for traffic from the AMF.
...

0

There are 0 best solutions below