Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Unable to access applicaton on port 8080 when using host network mode on Windows #11802

Closed
fugasjunior opened this issue May 8, 2024 · 1 comment

Comments

@fugasjunior
Copy link

Description

I have a Docker image with an application running on port 8080. When trying to run the application with network_mode: host, the port is not accessible from the host system. Running the same compose file on Linux works fine.

I am using Docker Desktop v4.30.0 with host networking enabled on Windows 11 Version 10.0.22631 Build 22631.

Steps To Reproduce

  1. Start the following compose file:
services:
  db_test:
    image: mysql:8.3.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: "example"
      MYSQL_DATABASE: "armaservermanager_db"
      MYSQL_USER: "armaservermanager"
      MYSQL_PASSWORD: "example"
    ports:
      - "3306:3306"
    volumes:
      - armaservermanager_test-db:/var/lib/mysql

  armaservermanager_test:
    image: "fugasjunior/armaservermanager:latest"
    restart: always
    network_mode: host
    depends_on:
      - db_test
    volumes:
      - armaservermanager_test-storage:/home/steam/armaservermanager/
    environment:
      AUTH_USERNAME: "test"
      AUTH_PASSWORD: "test"
      SPRING_DATASOURCE_URL: "jdbc:mysql://localhost:3306/armaservermanager_db"
      SPRING_DATASOURCE_USERNAME: "armaservermanager"
      SPRING_DATASOURCE_PASSWORD: "example"
      STEAM_API_KEY: "abcd1234"
      JWT_SECRET: "abcdefghijklmnopqrstuvwxyz123456789"

volumes:
  armaservermanager_test-db:
  armaservermanager_test-storage:
  1. Wait until Tomcat started on port(s): 8080 (http) with context path '' is visible in the output.
  2. Try to access http://localhost:8080 using any browser on host system.
  3. Observe that the application is not accessible from the host.

Compose Version

`docker compose version`
Docker Compose version v2.27.0-desktop.2

`docker-compose version`
Docker Compose version v2.27.0-desktop.2

Docker Environment

Client:
 Version:    26.1.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.14.0-desktop.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.27.0-desktop.2
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.29
    Path:     C:\Program Files\Docker\cli-plugins\docker-debug.exe
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     C:\Program Files\Docker\cli-plugins\docker-dev.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.23
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.4
    Path:     C:\Program Files\Docker\cli-plugins\docker-feedback.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.1.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scout: Docker Scout (Docker Inc.)
    Version:  v1.8.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 2
  Running: 2
  Paused: 0
  Stopped: 0
 Images: 8
 Server Version: 26.1.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: e377cd56a71523140ca6ae87e30244719194a521
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
 Kernel Version: 5.15.90.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 15.58GiB
 Name: docker-desktop
 ID: e4c1c101-3b9d-43f5-80f0-66f1ebb06ff8
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=npipe://\\.\pipe\docker_cli
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile

Anything else?

The port 8080 isn't listed when running netstat -aon on the host system.

When execing directly into the container, I can successfuly wget http://localhost:8080 and get a correct HTML page.

Pinging local network machines from the container works, so it seems to be using the host network correctly. The application is also able to connect to the database on localhost:3306.

Output of docker inspect
[
    {
        "Id": "c6a1556e0e6d5fa29ed489ccd356ab77429899495214b65469570003b43f83f3",
        "Created": "2024-05-08T09:17:52.470099748Z",
        "Path": "java",
        "Args": [
            "-jar",
            "./app.jar"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 8086,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2024-05-08T09:18:00.041088769Z",
            "FinishedAt": "2024-05-08T09:17:59.805368428Z"
        },
        "Image": "sha256:11f11724aad99b223c0b2749dc15da317edffd27e01dafebdf2f6b1ce51aba34",
        "ResolvConfPath": "/var/lib/docker/containers/c6a1556e0e6d5fa29ed489ccd356ab77429899495214b65469570003b43f83f3/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/c6a1556e0e6d5fa29ed489ccd356ab77429899495214b65469570003b43f83f3/hostname",
        "HostsPath": "/var/lib/docker/containers/c6a1556e0e6d5fa29ed489ccd356ab77429899495214b65469570003b43f83f3/hosts",
        "LogPath": "/var/lib/docker/containers/c6a1556e0e6d5fa29ed489ccd356ab77429899495214b65469570003b43f83f3/c6a1556e0e6d5fa29ed489ccd356ab77429899495214b65469570003b43f83f3-json.log",
        "Name": "/downloads-armaservermanager_test-1",
        "RestartCount": 2,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "host",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "always",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                0,
                0
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": [],
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "Mounts": [
                {
                    "Type": "volume",
                    "Source": "downloads_armaservermanager_test-storage",
                    "Target": "/home/steam/armaservermanager",
                    "VolumeOptions": {}
                }
            ],
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware",
                "/sys/devices/virtual/powercap"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/84f099702a3be5a0085d34b5e3dc5b3aa46d446a95d9ad593e983a9d5f4fa8be-init/diff:/var/lib/docker/overlay2/6a92f3489bd3902c6388e69b0d89fd92963affe74321b423d5e53602e478c176/diff:/var/lib/docker/overlay2/b35b3142eac3c35ea4e440abed683daa89ded3045099fa780db94c368bd2ddc6/diff:/var/lib/docker/overlay2/1fc7251cedef3405cdd5bd7762e71ffafbbf4f50b0ea51cfee9c0e374aa84e22/diff:/var/lib/docker/overlay2/b8b25467447eb2097b9309dd6176c765b8805d42d75c2f3514f181eccff8e41a/diff:/var/lib/docker/overlay2/2e860e1e34e82adad541089bc2171e79f938ac2fe4887dc2de8dbe3c58e86342/diff:/var/lib/docker/overlay2/76504a83f21f3df2b9abb0c9738e382646f4c4489b97d773af5d031fd544a26a/diff:/var/lib/docker/overlay2/69bf0a6d123bc9d137f13c99d9083fe2be0ba529a2cb1f3c54a3098a56949fb7/diff:/var/lib/docker/overlay2/9ff08580815cd16c65724507f8c6885e556f943bd8d77c82ce50ac1938f5bf26/diff",
                "MergedDir": "/var/lib/docker/overlay2/84f099702a3be5a0085d34b5e3dc5b3aa46d446a95d9ad593e983a9d5f4fa8be/merged",
                "UpperDir": "/var/lib/docker/overlay2/84f099702a3be5a0085d34b5e3dc5b3aa46d446a95d9ad593e983a9d5f4fa8be/diff",
                "WorkDir": "/var/lib/docker/overlay2/84f099702a3be5a0085d34b5e3dc5b3aa46d446a95d9ad593e983a9d5f4fa8be/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "downloads_armaservermanager_test-storage",
                "Source": "/var/lib/docker/volumes/downloads_armaservermanager_test-storage/_data",
                "Destination": "/home/steam/armaservermanager",
                "Driver": "local",
                "Mode": "z",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "docker-desktop",
            "Domainname": "",
            "User": "root",
            "AttachStdin": false,
            "AttachStdout": true,
            "AttachStderr": true,
            "ExposedPorts": {
                "8080/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "JWT_SECRET=abcdefghijklmnopqrstuvwxyz123456789",
                "AUTH_USERNAME=test",
                "AUTH_PASSWORD=test",
                "SPRING_DATASOURCE_URL=jdbc:mysql://localhost:3306/armaservermanager_db",
                "SPRING_DATASOURCE_USERNAME=armaservermanager",
                "SPRING_DATASOURCE_PASSWORD=example",
                "STEAM_API_KEY=abcd1234",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "USER=steam",
                "HOMEDIR=/home/steam",
                "STEAMCMDDIR=/home/steam/steamcmd",
                "APP_VERSION=1.2.0",
                "LANG=en_US.UTF-8",
                "LANGUAGE=en_US.UTF-8",
                "LC_ALL=en_US.UTF-8",
                "STEAMCMD_PATH=/home/steam/steamcmd/steamcmd.sh",
                "DIRECTORY_SERVERS=/home/steam/armaservermanager/servers",
                "DIRECTORY_MODS=/home/steam/armaservermanager/mods",
                "DIRECTORY_LOGS=/home/steam/armaservermanager/logs"
            ],
            "Cmd": [
                "-jar",
                "./app.jar"
            ],
            "Image": "fugasjunior/armaservermanager:latest",
            "Volumes": null,
            "WorkingDir": "/home/steam",
            "Entrypoint": [
                "java"
            ],
            "OnBuild": null,
            "Labels": {
                "com.docker.compose.config-hash": "ef5897285478d6d826df8696798abd834086f222f27eae02876ecb62d9df7ddb",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.depends_on": "db_test:service_started:false",
                "com.docker.compose.image": "sha256:11f11724aad99b223c0b2749dc15da317edffd27e01dafebdf2f6b1ce51aba34",
                "com.docker.compose.oneoff": "False",
                "com.docker.compose.project": "downloads",
                "com.docker.compose.project.config_files": "C:\\Users\\fugasjunior\\Downloads\\docker-compose.yml",
                "com.docker.compose.project.working_dir": "C:\\Users\\fugasjunior\\Downloads",
                "com.docker.compose.service": "armaservermanager_test",
                "com.docker.compose.version": "2.27.0",
                "maintainer": "walentinlamonos@gmail.com"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "208d6a2141a9745b21f70a25e96e25b679ce036e8858276a891324f032c7b954",
            "SandboxKey": "/var/run/docker/netns/default",
            "Ports": {},
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "host": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "MacAddress": "",
                    "NetworkID": "e9fb72fb3afb1318dfec5c91659a0879218837be1a8a909599f125d4fe4987ba",
                    "EndpointID": "627a034fa5ab562b2cfd0b9dc09ca79b000e1726a30d93df3bd9539bfa7d75ed",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "DriverOpts": null,
                    "DNSNames": null
                }
            }
        }
    }
]
@ndeloof
Copy link
Contributor

ndeloof commented May 24, 2024

Same applies to a plain docker run. When network mode is set to host, your container uses the host network interface without any abstraction. When running on Docker Desktop this one is the Virtual machine network interface, not localhost.
Please report this issue on https://github.com/docker/for-mac as this is unrelated to docker compose

@ndeloof ndeloof closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants