34

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).

3
  • Presumably TCP. Didn't test myself, I just cribbed it from here. See also this. 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. Feb 4, 2020 at 16:41
  • 3
    The default is TCP. Feb 4, 2020 at 16:41
  • And if I want both? Do I specify the same port twice with different protocols? Feb 4, 2020 at 16:51

2 Answers 2

60

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"
3
  • 1
    And what if I want both? Do I then add two records for the same port range? Feb 4, 2020 at 16:48
  • 2
    @MathiasLykkegaardLorenzen Yes, however be aware of this currently open issue
    – Piotr
    Oct 11, 2020 at 8:42
  • 2
    Just for future records (or the link breaks) the open issue is now fixed (1.29.2) and the above format should work as expected.
    – David
    Oct 3, 2021 at 1:49
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.