4

I have a spring boot application. On request it executes tcpdump as shown below

String cmd = "tcpdump -n host " + this.host;
Process process = Runtime.getRuntime().exec(cmd);
InputStream stream = process.getInputStream();
...

I wanted to dockerize this application to work on other OS than linux so i prepared Dockerfile:

FROM openjdk:15-alpine

RUN apk --no-cache add tcpdump
COPY target/app.jar /usr/src/app.jar

CMD java ... (runs spring app)

and docker-compose

version: '3.5'

services:
  service_name:
    network_mode: host
    container_name: service_name
    build:
      context: .
    environment:
      - TZ=Europe/Warsaw
      - spring.profiles.active=development
      - spring.liquibase.contexts=development

I expected network_mode: host to make docker use host network so it could be scanned and that it could receive on request to spring applications, but as tests have shown me that is not the case. Why and how can i fix that?

I've read in docs that:

Because of the way networking is implemented in Docker Desktop for Windows, you cannot see a docker0 interface on the host. This interface is actually within the virtual machine.

Does that mean, that i cannot connect to host machnine from docker on windows? How can i awoid that?

wokstym
  • 143
  • 1
  • 1
  • 12
  • Did you try `host.docker.internal` which resolves to the host machine IP? Like `tcpdump -n host.docker.internal` – Nagaraj Tantri Apr 14 '21 at 14:27
  • Host shown in snipet refers for host/website that we perform tcpdump, e.g. YouTube.com – wokstym Apr 14 '21 at 14:48
  • 1
    So, while your question mentions getting details about the host network. Could you provide more details on what is that you are trying to achieve here via `tcpdump`? Are you trying to check if there was any query to YouTube.com or a similar hostname? – Nagaraj Tantri Apr 14 '21 at 15:24
  • Goal is to have a application running on user computer that scans specific websites throughput and save it. – wokstym Apr 15 '21 at 09:43

0 Answers0