# UDP socket host-container doesnt work

**URL:** <https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605>\
**Category:** Docker Desktop\
**Tags:** windows, host-network\
**Created:** [December 20, 2024, 6:44am UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605 "2024-12-20T06:44:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabilmillan62](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gabilmillan62/32/54874_2.png) [@gabilmillan62](https://forums.docker.com/u/gabilmillan62)\
**Post date:** [December 20, 2024, 6:45am UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605/1 "2024-12-20T06:45:00Z")

</div>

Hi

I have an Ubuntu 22.04 host system running a container Ubuntu 24.04. I’m using Docker Desktop 4.36.0.

Container params:

```auto
"--hostname=devcontainer",
"--network=host",
"--privileged"·

```

Im testing a basic udp echo server:

`cat udp_server_echo.c`

```cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>

#define PORT 12345 /
#define BUFFER_SIZE 1024

int main() {
int sockfd;
struct sockaddr_in6 servaddr, clientaddr;
char buffer[BUFFER_SIZE];
socklen_t addr_len;
ssize_t n;

sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
if (sockfd < 0) {
perror("Error al crear el socket");
exit(EXIT_FAILURE);
}

memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin6_family = AF_INET6;
servaddr.sin6_port = htons(PORT);
servaddr.sin6_addr = in6addr_any;

if (bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
perror("Error en bind");
close(sockfd);
exit(EXIT_FAILURE);
}

printf("Server UDP IPv6 listening on port %d...\n", PORT);

addr_len = sizeof(clientaddr);
while (1) {

n = recvfrom(sockfd, buffer, BUFFER_SIZE - 1, 0,
(struct sockaddr *)&clientaddr, &addr_len);
if (n < 0) {
perror("Error al recibir datos");
continue;
}

buffer[n] = '\0';
char client_ip[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &clientaddr.sin6_addr, client_ip, sizeof(client_ip));
printf("Msg received from %s:%d: %s\n",
client_ip, ntohs(clientaddr.sin6_port), buffer);

n = sendto(sockfd, buffer, n, 0, (struct sockaddr *)&clientaddr, addr_len);
if (n < 0) {
perror("Error al enviar datos");
} else {
printf("Msg sent back to %s:%d\n",
client_ip, ntohs(clientaddr.sin6_port));
}
}

close(sockfd);
return 0;
}

```

On the client side (host):  
`echo "Hola, servidor!" | nc -u -6 ::1 12345`

ON the server side (inside the container):

```auto
./udp_server_echo
Server UDP IPv6 listening on port 12345...
Msg received from ::1:58520: Hola, servidor!

Mensaje sent back to ::1:58520

```

But the client doesnt receive back the message.  
tcpdump or wireshark only shows the udp resquest, there is not response in the socket.

Am I missing something?

Best regards.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/bluepuma77/32/32688_2.png) [@bluepuma77](https://forums.docker.com/u/bluepuma77)\
**Post date:** [December 20, 2024, 7:32am UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605/2 "2024-12-20T07:32:14Z")

</div>

Is your echo server working without Docker and without Docker Desktop (which adds a VM as another layer)?

---

<div class="post-metadata">

**Author:** ![gabilmillan62](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gabilmillan62/32/54874_2.png) [@gabilmillan62](https://forums.docker.com/u/gabilmillan62)\
**Post date:** [December 20, 2024, 11:29am UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605/3 "2024-12-20T11:29:11Z")

</div>

Hi.  
Docker Desktop 4.36.0  
Docker engine

```auto
$ docker --version
Docker version 27.4.1, build b9d17ea

```

Container details:  
`$ docker inspect objective_margulis`

```auto
[
    {
        "Id": "19934c121f40a74beb3517620c0081dcb5a754093ff9dc65f8429f9d20ecb212",
        "Created": "2024-12-20T08:02:08.527350812Z",
        "Path": "/bin/sh",
        "Args": [
            "-c",
            "echo Container started\ntrap \"exit 0\" 15\n\nexec \"$@\"\nwhile sleep 1 \u0026 wait $!; do :; done",
            "-"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 43257,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2024-12-20T08:02:08.657910163Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:319dce69cb02ada51436499cdd76b06bd065b94b0c88e67ab14bcfb800561380",
        "ResolvConfPath": "/var/lib/docker/containers/19934c121f40a74beb3517620c0081dcb5a754093ff9dc65f8429f9d20ecb212/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/19934c121f40a74beb3517620c0081dcb5a754093ff9dc65f8429f9d20ecb212/hostname",
        "HostsPath": "/var/lib/docker/containers/19934c121f40a74beb3517620c0081dcb5a754093ff9dc65f8429f9d20ecb212/hosts",
        "LogPath": "/var/lib/docker/containers/19934c121f40a74beb3517620c0081dcb5a754093ff9dc65f8429f9d20ecb212/19934c121f40a74beb3517620c0081dcb5a754093ff9dc65f8429f9d20ecb212-json.log",
        "Name": "/objective_margulis",
        "RestartCount": 0,
        "Driver": "overlayfs",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": [
            "72c3e09daee4c3504889d6969b071cb970c1ef2db28e45ef7bdcc14aa32a709e",
            "d19da184fd22a185c184cab231c0f8bc7c59d6a622b53be3fc9e03ae25794e55",
            "096837f1a272a09cbfef48f8d3009159e33aa9a7dd68a89145c817ab7c2e3390",
            "c4d7beaa9bab7cc4dbe69f650ff7d834acaf7d265bf18f8442d2d7423cb2d0c6",
            "986da13f24cbf787f319c200fe14e3b6aca00195279701c45f94c05ce9dbcdd6",
            "6c5f83d47e63b7f3e4a7afc616512ff2ad66282f6c5b8c4615c5e35ef4f227f4",
            "8c1529e4479ef8bb331fe338142280d80d5e5c4ae2adc4df92296f6860193221",
            "c50738ed708e893f70d87ea219367af2b2620d0144e5e3f2158c58f251748f40",
            "9723e6b5cdcd307bc5e630ff06a70d4cd7091f1c45fc46e1f7a32908ae696159"
        ],
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "host",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                24,
                80
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "private",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": true,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": [
                "label=disable"
            ],
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": [],
            "BlkioDeviceWriteBps": [],
            "BlkioDeviceReadIOps": [],
            "BlkioDeviceWriteIOps": [],
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": null,
            "PidsLimit": null,
            "Ulimits": [],
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "Mounts": [
                {
                    "Type": "bind",
                    "Source": "/home/gabilm/zephyrbox-uoscore-uedhoc",
                    "Target": "/workspaces/zephyrbox-uoscore-uedhoc"
                },
                {
                    "Type": "volume",
                    "Source": "vscode",
                    "Target": "/vscode"
                }
            ],
            "MaskedPaths": null,
            "ReadonlyPaths": null
        },
        "GraphDriver": {
            "Data": null,
            "Name": "overlayfs"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/home/gabilm/zephyrbox-uoscore-uedhoc",
                "Destination": "/workspaces/zephyrbox-uoscore-uedhoc",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "volume",
                "Name": "vscode",
                "Source": "/var/lib/docker/volumes/vscode/_data",
                "Destination": "/vscode",
                "Driver": "local",
                "Mode": "z",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "devcontainer",
            "Domainname": "",
            "User": "ubuntu",
            "AttachStdin": false,
            "AttachStdout": true,
            "AttachStderr": true,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/home/ubuntu/zephyrproject/.venv/bin:/home/ubuntu/zephyrproject/.venv/bin:/home/ubuntu/zephyrproject/.venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "VIRTUAL_ENV=/home/ubuntu/zephyrproject/.venv"
            ],
            "Cmd": [
                "-c",
                "echo Container started\ntrap \"exit 0\" 15\n\nexec \"$@\"\nwhile sleep 1 \u0026 wait $!; do :; done",
                "-"
            ],
            "Image": "vsc-zephyrbox-uoscore-uedhoc-b52d6c82dab1c57cb16c89decef305f18b3e3cf832be32cde088c9be8a0b65c1-uid",
            "Volumes": null,
            "WorkingDir": "/home/ubuntu/zephyrproject/zephyr",
            "Entrypoint": [
                "/bin/sh"
            ],
            "OnBuild": null,
            "Labels": {
                "devcontainer.config_file": "/home/gabilm/zephyrbox-uoscore-uedhoc/.devcontainer/devcontainer.json",
                "devcontainer.local_folder": "/home/gabilm/zephyrbox-uoscore-uedhoc",
                "devcontainer.metadata": "{\"postCreateCommand\":\"uname -a\",\"waitFor\":\"initializeCommand\",\"customizations\":{\"vscode\":{\"settings\":{\"C_Cpp.default.includePath\":[\"/home/ubuntu/zephyrproject/zephyr/include\"],\"editor.formatOnSave\":true,\"editor.codeActionsOnSave\":{\"source.organizeImports\":\"always\"},\"editor.rulers\":[80]},\"extensions\":[\"mhutchie.git-graph\",\"ms-vscode.cpptools-extension-pack\",\"mcu-debug.debug-tracker-vscode\",\"marus25.cortex-debug\",\"ms-vscode.cmake-tools\",\"twxs.cmake\",\"alphabotsec.vscode-eclipse-keybindings\",\"streetsidesoftware.code-spell-checker\"]}},\"forwardPorts\":[61234]}",
                "org.opencontainers.image.ref.name": "ubuntu",
                "org.opencontainers.image.version": "24.04"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "dbc57ac377e3b90c798e2c8af66a64fe79281f2c7626dd89b00b9bb09a7c2a70",
            "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": "",
                    "DriverOpts": null,
                    "NetworkID": "69e086fbf8c5bb39f194a82c320f16432e6a9777e5b799e5ac2e66d7897b9024",
                    "EndpointID": "bd9e35744b80880a03cf96eb1fc50c5e31f079cf91bcc4948170dc548426b821",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "DNSNames": null
                }
            }
        }
    }
]

```

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/bluepuma77/32/32688_2.png) [@bluepuma77](https://forums.docker.com/u/bluepuma77)\
**Post date:** [December 21, 2024, 2:56pm UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605/4 "2024-12-21T14:56:29Z")

</div>

Thanks for what? I asked a question and you dump unformatted JSON here.

---

<div class="post-metadata">

**Author:** ![gabilmillan62](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gabilmillan62/32/54874_2.png) [@gabilmillan62](https://forums.docker.com/u/gabilmillan62)\
**Post date:** [December 21, 2024, 4:36pm UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605/5 "2024-12-21T16:36:12Z")

</div>

Thanks for the time to read the post. Even if it is not what you asked.  
Yes, the service runs without Docker and docker desktop.  
The json includes the details of the container, just in case it can help.

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [December 22, 2024, 8:40pm UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605/6 "2024-12-22T20:40:48Z")

</div>

> [@gabilmillan62](#):
>
> The json includes the details of the container, just in case it can help.

* * *

Please, always format your posts according to the following guide: [How to format your forum posts](https://forums.docker.com/t/how-to-format-your-forum-posts/127295)  
In short: please, use `</>` button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

Example code block:

````auto
```
echo "I am a code."
echo "An athletic one, and I wanna run."
```

````

I fixed your previous posts this time.

* * *

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [December 22, 2024, 8:47pm UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605/7 "2024-12-22T20:47:02Z")

</div>

> [@gabilmillan62](#):
>
> echo “Hola, servidor!” | nc -u -6 ::1 12345

Have you tried it on IPv4?

---

<div class="post-metadata">

**Author:** ![gabilmillan62](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gabilmillan62/32/54874_2.png) [@gabilmillan62](https://forums.docker.com/u/gabilmillan62)\
**Post date:** [December 26, 2024, 10:25pm UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605/8 "2024-12-26T22:25:54Z")

</div>

Thank rimelek.  
Yes, I have tried it on IPv4 and IPv6 on localhost. Same result.

---

<div class="post-metadata">

**Author:** ![gabilmillan62](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gabilmillan62/32/54874_2.png) [@gabilmillan62](https://forums.docker.com/u/gabilmillan62)\
**Post date:** [January 2, 2025, 12:10pm UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605/9 "2025-01-02T12:10:53Z")

</div>

I have tried with a TCP echo server and it works fine from host to container, Still blocked with UDP. Any idea?

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [January 2, 2025, 1:06pm UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605/10 "2025-01-02T13:06:49Z")

</div>

If TCP works and UDP doesn’t, you can report the issue on gitHub

> **[GitHub - docker/for-win: Bug reports for Docker Desktop for Windows](https://github.com/docker/for-win)**
>
> Bug reports for Docker Desktop for Windows

Only protocols below UDP and TCP are not supported

---

<div class="post-metadata">

**Author:** ![gabilmillan62](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gabilmillan62/32/54874_2.png) [@gabilmillan62](https://forums.docker.com/u/gabilmillan62)\
**Post date:** [January 3, 2025, 7:54am UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605/11 "2025-01-03T07:54:17Z")

</div>

ok, I will report it in the docker/for-linux.

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/docker/original/3X/d/4/d4fbccd46c81bfcffe9822e20e17736d946fa821.png) [@system](https://forums.docker.com/u/system)\
**Post date:** [January 13, 2025, 7:54am UTC](https://forums.docker.com/t/udp-socket-host-container-doesnt-work/145605/12 "2025-01-13T07:54:43Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
