Config for docker ports udp

I have a working terraform config file for a docker container below.
It correctly works and forwards the TCP ports for the DNS server running in the container, however as it’s DNS I also want to forward UDP, can anyone tell me how to do this I found I need to use the “protocol” config item somewhere but can’t seem to work out where:

terraform {
required_providers {
docker = {
source = “kreuzwerker/docker”
version = “~> 2.13.0”
}
}
}

provider “docker” {}

resource “docker_image” “brett-nsd” {
name = “brett-nsd:latest”
keep_locally = false
}

resource “docker_container” “brett-nsd” {
image = docker_image.brett-nsd.latest
name = var.container_name
ports {
internal = 53
external = 5353
}
}

Have you checked the documentation? Terraform Registry

Yes indeed I have and that’s how I worked out I need to use the “protocol” config option to specify udp (tcp is default), but as there is no example and I’m pretty new to terraform I can’t work out where to insert the protocol config. I’ve tried a few different options which led to errors, so thought I’d try and get some help here.
Thanks
Brett

I’ve now worked out that this:

ports {
protocol = “tcp udp”
internal = 53
external = 5353

seems to be syntactically correct but when you apply you get this:

Error: Unable to start container: Error response from daemon: Ports are not available: listen udp 0.0.0.0:5353: bind: address already in use

│ with docker_container.brett-nsd,

│ on main.tf line 17, in resource “docker_container” “brett-nsd”:

│ 17: resource “docker_container” “brett-nsd” {

The below version also leads to the same error:

ports {
protocol = “tcp”
internal = 53
external = 5353
}
ports {
protocol = “udp”
internal = 53
external = 5353
}

I don’t think this is valid syntax.

This is, though, and works for me.

I guess you have something else using port 5353 where you are running this.