40

I know that I can specify the protocol of "ports" in the docker-compose.yml file, but I am unsure what the default protocol is, if no protocol is specified.

Is it TCP? Is it UDP? Both?

I haven't been able to find the answer anywhere (including in the Docker Compose file reference).

Mathias Lykkegaard Lorenzen
  • 15,031
  • 23
  • 100
  • 187
  • Presumably TCP. Didn't test myself, I just [cribbed it from here](https://stackoverflow.com/a/40801773/4137916). See also [this](https://github.com/moby/moby/issues/32958). The Dockerfile (not compose) docs also note that TCP is the default throughout for the `EXPOSE` section and port parameters, so compose doing the same would be consistent. – Jeroen Mostert Feb 04 '20 at 16:41
  • 4
    The default is TCP. – johnharris85 Feb 04 '20 at 16:41
  • And if I want both? Do I specify the same port twice with different protocols? – Mathias Lykkegaard Lorenzen Feb 04 '20 at 16:51

2 Answers2

73

by default TCP is used, you can see it launching docker-compose ps

If you want to specify you should add /udp or /tcp like :

ports:
  - "80:80/udp"
  - "80:80/tcp"
CocoBagarre
  • 796
  • 6
  • 7
3

In addition to above comment for me docker compose long syntax worked to open UDP port, do also check that your required port is open and available to cater request. https://docs.docker.com/compose/compose-file/compose-file-v3/#ports

ports:
 - target: 18123
   published: 18123
   protocol: udp
   mode: host
frankhommers
  • 1,169
  • 12
  • 26
SDV
  • 313
  • 2
  • 9